How to implement Role Based Authorization in T3?
Hey community,
I am new to the T3 stack and would like to implement role based authorization in my project. To ensure that only authorized users with the admin role can execute certain queries, I have created a new
adminProcedure
:
This works in theory, but somehow the roles of the users are not taken over correctly. My sessionCallback looks like this:
In my admin procedure, however, the role value always remains undefined. Does anyone have any idea what I am doing wrong or what I am missing? Thanks in advance!5 Replies
role: session.user.role, => role: user.role,
thx for the response, didn't work for me. implemented a fix by making a db request before asigning the role, which works just fine
I had a similar problem... Although I cant give you a concrete answer, you have to define all the callbacks and pass the user multiple times, or sometimes it doesn't reach the client side like you would expect
try going through the docs, writing the code for all callbacks, and console log all parameters so that you can better understand what goes where
You use oauth provider ?
I had like Credentials, Google, Discord and 1 custom one
but not oAuth