Add Admin Role to T3 Stack

Hi, not sure what I'm missing for this in user Schema
role Role @default(USER)
role Role @default(USER)
and then the enum for Role.. thats okay, --- Then I tried to make a protected middleware, and noticed that session.user is only showing 4 values, role is missing, but many others too (first picture), -- Adding role to next-auth.d.ts fixed the type definition and role appears, but the issue persists as it returns undefined instead of the role (second pic) Any idea? Not sure what I have to do to retrieve more than those 4 values from User schema Thanks šŸ™‚
8 Replies
Kenzo
KenzoOP•3y ago
------- like @nexxel said, these appears because they are default by Next? https://i.imgur.com/Tv9qx22.png
Imgur
Kenzo
KenzoOP•3y ago
--- How would you fetch the role for make the protected routes? and how normal values?
Kenzo
KenzoOP•3y ago
https://i.imgur.com/mCjzFaZ.png I guess this is the way? but role does not exists on that type
Imgur
brr
brr•3y ago
what you can do is start the user id with the role name e.g admin , then check that the first 4 letters of id are admin
Kenzo
KenzoOP•3y ago
@brr hey, actually this works, the session.user.role = user.role šŸ™‚ but.. it still gets the TS issue somehow I have to add a new role?
Property 'role' does not exist on type 'User | AdapterUser'.
Property 'role' does not exist on type 'User'.
Property 'role' does not exist on type 'User | AdapterUser'.
Property 'role' does not exist on type 'User'.
brr
brr•3y ago
hmm not sure sorry
Kenzo
KenzoOP•3y ago
Kenzo
KenzoOP•3y ago
with the role? it fixed the TS issues, ill close the post idk

Did you find this page helpful?