Admin login issue


#1

const admin = await AdminUser.query()
.where(‘email’, email)
.where(‘is_active’, true)
.first()
if(admin) {

			const hashVerify = await Hash.verify(password, admin.password)
			if(hashVerify){
				await auth.login(admin)
				return response.route('admin.home')
			}
		}

It redirect to admin home page but when i do check auth.check() into home controller it says invalid sessionException, please suggest

Thanks


#2

Hey @prolificdizine! :wave:

Could you please provide more information (like which Scheme you are using)?
The best would be to have a repository with the minimum amount of code to reproduce the issue.


#3

In admins table
table.string(‘name’, 80).notNullable()
table.string(‘email’, 254).notNullable().unique()
table.string(‘password’, 60).notNullable()

I just checked auth.js

session: {
serializer: ‘lucid’,
model: ‘App/Models/User’,
scheme: ‘session’,
uid: ‘email’,
password: ‘password’
},

If i change model: ‘App/Models/Admin’, works well but i want both accessible in case admin or user model


#4

I am not sure why you two tables at first place. admin is just a different role for the user.

And if you want to use to models, then define 2 Authenticators in the config file


#5

Just for testing i used this, so you mean

session: {
serializer: ‘lucid’,
model: ‘App/Models/User’,
scheme: ‘session’,
uid: ‘email’,
password: ‘password’
},

session: {
serializer: ‘lucid’,
model: ‘App/Models/Admin’,
scheme: ‘session’,
uid: ‘email’,
password: ‘password’
},

Like this ?


#6

Yeah but object keys have to be different. You cannot use session as a key twice.


#7

and then so more place need to amend i guess .?? I mean have to update other places too


#8

But I must say currently many package does the same things allow creates own table for login, laravel allows the same…


#9

I am sorry I don’t get what you trying to do. Please read the documentation carefully and ask specific questions. What x or y can do is not helpful for anyone


#10