How do I set up multiple authenticators in auth.js

I’ve created two models. Admin & User for my test application.
I need both of them to use Session authenticator.
In auth.js file I have set

 user: {
    serializer: "lucid",
    model: "App/Models/User",
    scheme: "session",
    uid: "email",
    password: "password"
  },
  admin: {
    serializer: "lucid",
    model: "App/Models/Admin",
    scheme: "session",
    uid: "email",
    password: "password"
  }

Now there is a key “authenticator” in this file. What do I set its value to?

2 Likes

Okay. I solved the issue. What you actually need to do is, make use of authenticator switching…
https://adonisjs.com/docs/4.1/authentication#_switching_authenticators

2 Likes

There is one issue. Say you have an admin and user with same ID, and you use middle-ware to protect your route, your logged in user can access the admin routes. Don’t know if it is a bug or I’ve messed up something in the implementation, but that’s how it works.

1 Like