fp-lua-session

This module is an express middleware and should resolve a session stored in a JWT and store the results in res.locals.session.

Usage no npm install needed!

<script type="module">
  import fpLuaSession from 'https://cdn.skypack.dev/fp-lua-session';
</script>

README

FP LUA Sessions

This module is an express middleware and should resolve a session stored in a JWT and store the results in res.locals.session.

{
    "dscaid": 1234,
    "dscid": 5555,
    "data": {
        "foo": "bar"
    },
    "groups": [
        123,
        456,
        789
    ],
    "roles": [
        "superadmin",
        "user",
        "docreader"
    ]
}

When initializing the module it should be possible to define if the "data" key is needed or can be omited.

Usage:

app.get("/some_endpoint", resolveSession, (req, res, next) =>  {
    console.log(res.locals.session)
    res.send("OK")
}
const resolveSession = (req, res, next) {
    // Try to find and decode the JWT
    if (no_session_found || error_decoding_the_JWT) {
        next({error: "No session", status: 403});
        return;
    }
    // Resolve the session from Redis
    if (no_session_found) {
         next({error: "No session", status: 403});
         return;
    }
    // Set res.locals.session to above format
    next();
}