How to use Multiple table for multiple authentication in adonisjs

Hello Guyz,
I am new here as well as adonis.Its an amazing framework. I am trying to use two different tables for multiple authentication. I am not using ‘users’ table. So how can i apply the authentication technique like laravel. I have followed
https://github.com/adonisjs/adonis-auth/issues/121 this link but sorry to say I didn’t understand clearly. Please feel free to ask anything.
Thanks in advance

1 Like

Hello man,

I have the same issue here. Were you able to solve it in any way?

Thanks a lot!

hi everyone!

In auth.js you can choose model type.

see sample

jwt: {
    serializer: 'lucid',
    model: 'App/Models/UserForum1',
    scheme: 'jwt',
    uid: 'email',
    password: 'password',
    options: {
      secret: `${Env.get('APP_KEY')}-forum1`,
    },
  },
  anotherAuth: {
    serializer: 'lucid',
    model: 'App/Models/UserForum2',
    scheme: 'jwt',
    uid: 'email',
    password: 'password',
    options: {
      secret: `${Env.get('APP_KEY')}-forum2`,
    },
  },

and your controller can access this authenticator

await auth.authenticator('anotherAuth').attempt(email, password);
5 Likes

It worked!

Oh Man! God Bless you!! Really!
I’ve been trying to solve this for 48hours !!!

You rock! Thank you so much.

7 Likes

glad to help! :grinning:

1 Like

Just complementing the answer, to whoever come to this post,

In your routes.js please don’t forget to put in your middlewares : “auth:anotherAuth”.

Like this:

Route.(…).middleware(‘auth:anotherAuth’)

Or it won’t work. :wink:

1 Like

What about Tokens, how can we setup the datatables so tokens can be issued for both types of Models?

Thanks Andre, you got me closer to my goal. I did get this error: E_INVALID_SESSION: Invalid session. Do yo think it’s because I’m on Adonis 4.1?

Thanks,
Jamie