Saving session to database


#1

Hi, would it be possible to have a database session? Much like Laravel database session driver.

Use case is for a stateful session for APIs, with micro-apps accessing it, and also a Session manager where an admin can revoke and monitor user session (see who’s online, revoke session, etc.).

Thanks


#2

Use redis for that


#3

Hi virk, currently it’s not possible for me to use redis. It’s more of a policy at work. Anyway, thanks for the reply. I might have to implement my own session handler and middleware. This is a nice to have though, since Laravel has it. I hope it will be considered in the future. Regards.


#4

You can add your own session driver, instead of re-creating the entire session module. Inside the start/hooks.js file, you can register your own driver.

hooks.before.providersRegistered(function () {
  ioc.extend('Adonis/Src/Session', 'database', function () {
     return new DatabaseDriver()
  })
})

And then implement DatabaseDriver by referring the code here https://github.com/adonisjs/adonis-session/blob/develop/src/Session/Drivers/Redis.js