-
Notifications
You must be signed in to change notification settings - Fork 0
Restrict guest access before dashboard #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { NextResponse } from 'next/server' | |||
| const PUBLIC_ROUTES = ['/', '/auth/login', '/auth/sign-up'] | ||||
|
|
||||
| // Routes that allow guest access | ||||
| const GUEST_ALLOWED_ROUTES = ['/dashboard', '/food-details', '/api/foods'] | ||||
| const GUEST_ALLOWED_ROUTES = ['/food-details', '/api/foods'] | ||||
|
|
||||
| // Check if Supabase is configured | ||||
| function isSupabaseConfigured(): boolean { | ||||
|
|
@@ -32,8 +32,12 @@ export async function middleware(request: NextRequest) { | |||
| path.startsWith(route) | ||||
| ) | ||||
|
|
||||
| if (isGuestMode && isGuestAllowedRoute) { | ||||
| return response | ||||
| if (isGuestMode) { | ||||
| if (isGuestAllowedRoute) { | ||||
| return response | ||||
| } | ||||
|
|
||||
| return NextResponse.redirect(new URL('/auth/login', request.url)) | ||||
| } | ||||
|
|
||||
| // If Supabase is not configured, handle routes without authentication | ||||
|
|
@@ -43,32 +47,30 @@ export async function middleware(request: NextRequest) { | |||
| } | ||||
|
|
||||
| // Only create Supabase client and check session if NOT in guest mode | ||||
|
||||
| // Only create Supabase client and check session if NOT in guest mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing
/dashboardfrom the guest-allowed list means requests with theguestModecookie now hit this branch and are redirected to/auth/login. TheGuestModeButtonstill sets that cookie and routes guests to/dashboard, so “Continue as Guest” immediately bounces back to the login page and the guest dashboard experience is unreachable. Consider keeping/dashboardguest-accessible or update the guest entry point/target so the guest flow still lands on an allowed page.Useful? React with 👍 / 👎.