Best practice for Admin dashboard?

I want to make an admin special page, but on the client side, I didn't know how to check if the user is admin, how can I do it? Should I check if the id from ctx is admin with getServerSideProps or should I check with trpc query? I want to do something like layout
25 Replies
robotkutya
robotkutya2y ago
In the create-t3-app starting template there is this part:
getSecretMessage: protectedProcedure.query(() => {
return "you can now see this secret message!";
}),
getSecretMessage: protectedProcedure.query(() => {
return "you can now see this secret message!";
}),
I recommend you go over that and follow that to the front end. If you have more questions lemme know 🖖
Çağlar
Çağlar2y ago
@robotkutya thank you very much, I would like to ask about handling on the client side like do I need some kind of provider layout or idk And it would be amazing if you could give me an example template
barry
barry2y ago
You don't check on the client side.
Çağlar
Çağlar2y ago
then what should I do? do you have any sample?
c
c2y ago
not sure that this is best practice, but it's a middleware implementation w/ jwt: https://discord.com/channels/966627436387266600/1067624837507457034/1068639470896824320
Çağlar
Çağlar2y ago
how did u assign role to token? where did you take it from? I couldn't add a role or isAdmin (boolean type) to session.user object in callbacks. isAdmin or role is constantly returning undefined. It exists in the schema and I define 'user' by default, but it returns undefined no matter what I do btw Im using credentials provider
barry
barry2y ago
did you make the user before adding role
Çağlar
Çağlar2y ago
Yes I did
barry
barry2y ago
there you have the reason its undefined lol
Çağlar
Çağlar2y ago
Nope, it shouldnt have be undefined. I set User as the default value.
barry
barry2y ago
if a user exists without a role column, and you add role to the table it goes undefined not default
Çağlar
Çağlar2y ago
No, I mean there is a role column and its default value is User.
barry
barry2y ago
and you said the user was there before you added the role column
Çağlar
Çağlar2y ago
I wasnt mean that I'm sorry if I expressed it wrong
c
c2y ago
hard to help much without code to look at. i actually had trouble doing this just based off of docs but you can try doing what i did and just reading through all the nextauth/trpc example reps and searching through past issues for other code examples.
Want results from more Discord servers?
Add your server