Skip to content

4. Session

leonardo Rico edited this page Jan 21, 2018 · 3 revisions

When you log in correctly the information arrives here: /src/auth/services/session.js

Params

  • err: errors
  • user: user from data base
  • res: response

Lines of interest

Calculate ttl by user roles

let ttl = calc(time(config.roles, user.roles), 'max');

More info: role-calc

Create session in redis-jwt

 const token = await r.sign(user._id.toString(), { // id user
   ttl: '15 minutes',// examples: 50 seconds, 10 minutes, 5 hours, 3 days
   dataSession: { obj }, // save data in REDIS (Private)
   dataToken: { obj }, // save data in Token (Public)
});

More info: redis-jwt

Note

  • The generated token will be returned for the client to store in localstorage or cookies
  • The token will be sent in the "Authorization" header on each request from client, to see how to extract it and validate, see Middleware
Clone this wiki locally