multi role implementation
Unanswered
TyZreX posted this in #help-forum
TyZreXOP
I have like components for the admin already and I need a moderator role to be added which is a subset of the components of the admin role the url can be the same as admin/something but just need to filter out the components on the basis of role like payments not to be seen by the moderator
14 Replies
TyZreXOP
@riský
What I currently have is an admin route which can be accessed from /admin
And there are like pages for payments, user data like
Admin/user
Admin/payments
And others like blogs which needs to be shared to moderator as well
Admin/user
Admin/payments
And others like blogs which needs to be shared to moderator as well
I was thinking about creating a (admin-only) and a (shared) route group and check the roles in the layouts is this the way to do it or is there any thing else a better approah
check the roles in the layoutsso you see this is not fully safe, you can check there and give good error, but you have to add the check on every page as you can request the page with no layout (and thus bypassing it)
TyZreXOP
Oh so do I just get the session in every page and check for the role there?
well is this server component or client fetch
TyZreXOP
There are client components for the entry of data for forms but all the data is fetched in the main server components and is getting passed down to the client ones
The structure for each page is like a view page
Page.tsx which houses the table to see everything this is server side
And add-something route inside it to entry the data in the forms
Page.tsx which houses the table to see everything this is server side
And add-something route inside it to entry the data in the forms
Also the role gets checked in the middle ware to protect the main /admin page
Which runs for all /admin*
well thats safer then
TyZreXOP
So should I just check in every page or create a route group
Or maybe should I just create a admin/shared and put everything inside here that needs to be shared and check the roles in the middleware