How to get separated auth for admin and user models in Adonis JS #2738
Replies: 4 comments 6 replies
-
It's possible. First thing you need is to understand how can you create a custom user provider. After that take a look at the interface /**
* Returns the user instance by searching the uidValue against
* their defined uids.
*/
async findByUid(uidValue) {
const model = await this.getModel();
/**
* Use custom function on the model. This time, we do not emit
* an event, since the user custom lookup may not even
* run a query at all.
*/
if (typeof model.findForAuth === 'function') {
const user = await model.findForAuth(this.config.uids, uidValue);
return this.getUserFor(user);
}
/**
* Lookup by running a custom query.
*/
const { query } = await this.getModelQuery();
this.config.uids.forEach((uid) => query.orWhere(uid, uidValue));
return this.findUser(query);
} As you can see this is one place where you'll get the model you want(if you're using BASIC guard, other guards rely on other methods as well). With your custom user provider you'll implement this method and choose the between Admins or Users as you can see fit... |
Beta Was this translation helpful? Give feedback.
-
Hello @guntribam Thanks for your reply. Let's Say I have two models. Kindly let me know. In short I want to create an application with Adonis that Have 2 or 3 Login. One for User and another for SuperAdmin and other for Admin. I am new to this. Kindly Help. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
@guntribam Can I get help ? It's very urgent. I have tried but it's not happening. May be I can't get the root of the process. So if you tell the way then It will be very much helpful. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to have separated Auth for different models in Adonis Js?
I have two different table for admins and users and want to have separated Auth.
How can I setup this in adonis js ?
Beta Was this translation helpful? Give feedback.
All reactions