Role based Auth
Answered
`icey tea dev` posted this in #help-forum
I've setup my own role based auth with JWT's.
When I authenticate a user, a store the JWT into a cookie using nextjs/headers.
I want to dynamically render my Nav bar depending on the user role (which I stored in the JWT).
Should I make my Nav Bar a server component (or should I make it a client component), and check the cookie from there to determine how the nav bar should be rendered, or should I make a call to a server action to get the role from the JWT and return that to the client. Should I be exposing the role to the client like that? That's probably a security risk.
What should I do for this situation.
When I authenticate a user, a store the JWT into a cookie using nextjs/headers.
I want to dynamically render my Nav bar depending on the user role (which I stored in the JWT).
Should I make my Nav Bar a server component (or should I make it a client component), and check the cookie from there to determine how the nav bar should be rendered, or should I make a call to a server action to get the role from the JWT and return that to the client. Should I be exposing the role to the client like that? That's probably a security risk.
What should I do for this situation.
Answered by Ray
Should I make my Nav Bar a server component (or should I make it a client component)I would only use client component where I need user interaction.
Should I be exposing the role to the client like that?depend on your app, if you need the role on client side
21 Replies
@`icey tea dev` I've setup my own role based auth with JWT's.
When I authenticate a user, a store the JWT into a cookie using nextjs/headers.
I want to dynamically render my Nav bar depending on the user role (which I stored in the JWT).
Should I make my Nav Bar a server component (or should I make it a client component), and check the cookie from there to determine how the nav bar should be rendered, or should I make a call to a server action to get the role from the JWT and return that to the client. Should I be exposing the role to the client like that? That's probably a security risk.
What should I do for this situation.
Should I make my Nav Bar a server component (or should I make it a client component)I would only use client component where I need user interaction.
Should I be exposing the role to the client like that?depend on your app, if you need the role on client side
Answer
@Ray > Should I make my Nav Bar a server component (or should I make it a client component)
I would only use client component where I need user interaction.
> Should I be exposing the role to the client like that?
depend on your app, if you need the role on client side
I honestly just need the role to give admins extra tabs
would it be unsafe to decode it on the backend using some middleware?
and send it to the client
wait that makes no sense lol
no middleware
just a server action I guess
@`icey tea dev` I honestly just need the role to give admins extra tabs
are you able to render the tabs with server component?
nested layout is good for rendering tabs
@Ray are you able to render the tabs with server component?
I'm using a nested layout right now which holds my nav bar. When you say render the tabs with a server component, does that mean keeping the nav bar as a client component, and use a server component for the tabs of it?
so the actual nav bar is on the client, but those tabs are on rendered on the server?
I would just keep all in server component 😀
why you need it on client component?
I guess I don't really need it as a client component 😅
yea keep everything on server so you don't expose anything
yea I'll do that
when I use the server component in my layout I seem to get this issue here
in the React Client Manifest. This is probably a bug in the React Server Components bundler.@`icey tea dev`
in the React Client Manifest. This is probably a bug in the React Server Components bundler.
for anyone in the fuure, fixed this by removing
"use client from my layout component 🙂thanks @Ray for the help ðŸ™