Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛Bug: isAuth function crashing #89

Open
vlbee opened this issue Aug 17, 2018 · 0 comments
Open

🐛Bug: isAuth function crashing #89

vlbee opened this issue Aug 17, 2018 · 0 comments

Comments

@vlbee
Copy link

vlbee commented Aug 17, 2018

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");
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant