Skip to content

Movie sessions function out of server.js #58

@ko-karol

Description

@ko-karol

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions