adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
196 stars 64 forks source link

Bug in Multiple Authentication #126

Closed TMJEngineers closed 5 years ago

TMJEngineers commented 6 years ago

Hi,

I have notice that upon logging in on our admin auth it also fills in our user auth with the same id of the logged user. I have tested it on a fresh adonis setup to validate my claim. This is what I did and what is the result of it.

config/auth.js

screen shot 2018-09-28 at 9 39 39 am

Route

screen shot 2018-09-28 at 9 40 04 am

I only logged the auth of admin and console the both authenticator and these were the result.

Console

screen shot 2018-09-28 at 9 44 04 am screen shot 2018-09-28 at 9 43 57 am

Please see the id in $attributes

Did I use the authenticator the right way?

thetutlage commented 6 years ago

If you look at it closely, this is not a bug.

Your user login with an id of 1 let's say. Now you are asking both the authenticators, admin and user to find a user by querying the database for id=1.

If user for id=1 exists in users and also in admin table, that means they are logged in.

Also I don't understand the point of creating 2 users table. Ideally admin is a different role for the user and creating multiple tables for different roles will not help much

TMJEngineers commented 6 years ago

hi @thetutlage thank you for your reply, I think I understand the authenticators in a wrong way. I just want to know how do you handle different authentication in different database or table in adonis correctly? or is it supported?

On our end we have many reason why separate 2 tables but the summary of it is to simplify the process of fetching 2 type of users and to prevent other dev's specially newly joined dev from making a mistake on fetching users since the access level of each is crucial to the security of the application.

RomainLanz commented 5 years ago

Closing since issue hasn't been active for a while. Feel free to create a new one if needed.