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

Movie sessions function out of server.js #58

Open
ko-karol opened this issue Feb 1, 2023 · 0 comments
Open

Movie sessions function out of server.js #58

ko-karol opened this issue Feb 1, 2023 · 0 comments

Comments

@ko-karol
Copy link

ko-karol commented Feb 1, 2023

Seeing as we're requiring a bunch of modules already and just calling functions in server.js, it might be better to also do the same with the sessions function.

function sessions(req, res, next) {
    const sid = req.signedCookies.sid; //undefined if there is not a sid
    const session = getSession(sid); //undefined if there is no session
    if (session) {
        const expiry = new Date(session.expires_at);
        const today = new Date();
        if (expiry < today) {
            removeSession(sid);
            res.clearCookie('sid');
        } else {
            req.session = session;
        }
    }
    next();
}
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