Setting Admin Roll With Hook
here is my hook in my auth config
i checked that ctx.body.role = 'ADMIN' throughout this hook
but when the user is created in my database their role is 'USER'
I assume this comes from my
@default(USER)
on my prisma schema but why is this occuring if the role is set to user via the before hook?
originally I had this logic in databaseHooks but I moved it to hooks so that I can use the
required: true
flag on the [user][additional fields]
/* for now ill move logic back to databaseHooks */13 Replies
update i thought i found my mistake by not returning a context, as so
but ALAS the name gets changed but the role is still "USER" 😦
bump
Are you sure your logic is correct and that
if
statement does return true for role
to be admin?Pretty sure I did console logging throughout the hook
I can try again since I moved the logic for role to database hooks
I added the name just to show a 1-1 parallel and the name does get changed
Might be easier to test if you can hardcode role in the return to just be
ADMIN
and see if that works.no dice


this is how sign up is being called originally for reference although i assume this happens before the hook
@Ping still curious about this if you have the chance to check
Why not use database hooks again? @KHRM
no particular reason i just want to know if im doing something wrong
if i use hooks or even hard code it in the sign up
it just always is role USER
The admin plugin overwrites this, it makes sense because you wouldn't want malicious users be able to control the role to sign up via front-end.
If you can use a database hook - after hook, you can check if the email matches your list, then use your ORM to update their role.
I see fors the option of adminIds in the admin plugin override the role in the database? Or will set their role upon sign up although that kind of wouldn't make sense because you wouldn't know the id in advance
Basically database hooks is the intended way to work with role with admin plugin
If I'm not using admin plugin I could pass it via the sign up or a regular hook?
Yes, just as long as you're aware that it can be dangerous for the front-end to determine the role of a user
You'll have to code everything yourself - outside the admin plugin.
Got it thanks for clarifying why it was getting 'overridden'