Skip to content

🐛Bug: isAuth function crashing #89

Description

@vlbee

https://github.com/fac-14/KaMoSiMa/blob/master/src/router.js#L21

This line is throwing an error, both when I register and when I register and after I login, logout, and then try to access one of the protected routers: TypeError: Cannot read property 'logged_in' of undefined

Possible fix: if you don't use an 'if/else', you need to return your if error callback otherwise your function keeps running and the error gets thrown in line 21.

const isAuth = (userCookie, callback) => {
    if (userCookie) {
        console.log(`user provided cookie: ${userCookie}`);
        let parsedCookie = cookie.parse(userCookie);
        jwt.verify(parsedCookie['data'], process.env.JWT_SECRET, (err, decoded) => {
            if (err || !decoded) {
                return callback("error");
            }
            callback(null, decoded['logged_in']);
        });
    } else {
        callback("error");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions