Can i use two authentication types i.e JWT and session together?

#1

Hello good people,

I am new to adonisjs but i really like the framework, i will like to integrate it to the existing frontend and mobile applications that am working on but would like to know if i can use session auth type to authenticate users and jwt auth type to authenticate api calls.

1 Like

#2

Yes, just go through the documentation of Auth. http://adonisjs.com/docs/4.0/authentication#_switching_authenticators and also read about middleware.

You can specify the authenticator to be used for a given route

Route
  .post('api/v1/users', 'UserController.store')
  .middleware(['auth:jwt'])

Route
  .post('dashboard', 'HomeController.dashboard')
  .middleware(['auth:session'])
2 Likes

#3

Thank you sir, this is very helpful

0 Likes

#4

auth.login(user); not works.

how to genrate jwt and seesion on usr login.

0 Likes