Prevent authenticated user from navigating to admin cms in nextjs14 monorepo #5024
Replies: 3 comments
-
To summarize your issue, when a user fails the If we just provide a config property for redirecting them somewhere else that feels incomplete to me. Payload always provides meaningful defaults whenever possible so without setting that property and making a page for it you would have bad ux and it is bad dx to have to do that. Would it be expected to be redirected to From there we could use a new config property used to set the URL for a link to leave or log out in case they want to stay at the admin but log in with another account. How does this sound? |
Beta Was this translation helpful? Give feedback.
-
Hi Dan, Thanks for the reply. I agree with you, it is more like a feature and the /admin/unauthorized makes sense, of even just redirect to /login since the user is not authorized he/she should not be able to login, even if the payload-token exists in the cookies. In the meantime i found a workaround by adding a middleware before mounting payload:
where validateAccess is
|
Beta Was this translation helpful? Give feedback.
-
Hey @Lorentzo92 thanks for following up with your solution here. Gonna convert to discussion so others can find it! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to reproduction
No response
Describe the Bug
Hi,
We have a monorepo with nextjs14 app router and payload. In payload we have admins and users collections, only admin can access the admin panel.
The routes structure is:
The issues we have is: if i login in nextjs /login as users i am correctly redirected to /, now if i try to go to /cms then payload remains pending since i am a user and i cannot access the admin panel, but i am not redirected, i only get an consolo log error "you are not allowed to perform this action"
I read through the doc but i could find a way to redirect this scenario.
To Reproduce
i can provide code if needed
Payload Version
2.8.2
Adapters and Plugins
No response
Beta Was this translation helpful? Give feedback.
All reactions