Auth JWT, with many types of users

I have 4 types of users on my app, with different needs, tables and models. (Students, Parents, Admins, Affiliates)

I can’t generate the jwt token for each of them.

Has anyone done that with multiple models?

I find only 3 or 4 posts on Google about that. None of the solutions actually work.

Thank you so much.

Hi @Andre.Costa101 and welcome to community! :slight_smile:

Multi role auth is usually solved by multiple roles.

One option to solve it is something like this:
You can create 5 tables: users, students, parents, admins, affiliates

Users table will contain something like this:
id, email, password, role (this will be student, parent, admin etc…)
And then add user_id into students, parents etc.

Then only user is logged in and specific role data is attached

1 Like

Hey McSneaky thanks so much for the answer.

My problem is that Students won’t have an email like the others. Only a code that the parent will send him =(

Any ideas how I could get this done?
( and I apologize if this is way too simple; this is my first application)

thank you

There are no too simple questions :smiley: (just might get answer: read that part of documentation for something)

But current case makes it quite a bit more complicated.
I think I’d go with two authentication methods

Will students have password?
I’ll assume they have

I’d steal ideas from here:

And from here: Multi model in jwt authentication
So you would end up with something like this:

	user: {
	    serializer: 'lucid',
	    model: 'App/Models/User',
	    scheme: 'session',
	    uid: 'email',
	    password: 'password'
	student: {
	    serializer: 'lucid',
	    model: 'App/Models/Student',
	    scheme: 'session',
	    uid: 'code_field_that_parent_gives',
	    password: 'password'

Where user has email and password and covers all the other roles, expect student, who has code instead of email (uid)

I’m not exactly sure is changing secret needed or not


Thank you! I’ll try and report back here