Public Group, Auth Group, and Protected Group #80182
Unanswered
fahmiidris
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have three categories of pages in my Next.js app:
Public pages – Usually I create a folder like this: src/app(public)/. All pages in this group can be accessed by both logged-in and non-logged-in users.
Protected pages – I usually put them in: src/app(protected)/. These pages should only be accessible to users who are logged in.
Auth pages – I create a folder like this: src/app(auth)/. These pages should only be accessible to users who are not logged in, like /sign-in, /sign-up, etc.
What’s the best way to protect them?
The easiest way is to add a check inside the layout group. But the docs don’t recommend that approach.
I also looked into using middleware, but that means I have to manually define all the routes again – and I really don’t want to do that.
Do you get what I mean? I need a solution – thanks!
Beta Was this translation helpful? Give feedback.
All reactions