-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redirect on / to login or dashboard dep on session
- Loading branch information
1 parent
301b554
commit 9de9523
Showing
3 changed files
with
35 additions
and
7 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createSupabaseUserRouteHandlerClient } from '@/supabase-clients/user/createSupabaseUserRouteHandlerClient'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function GET() { | ||
const supabase = createSupabaseUserRouteHandlerClient(); | ||
|
||
const { | ||
data: { user }, | ||
error, | ||
} = await supabase.auth.getUser(); | ||
|
||
if (error) { | ||
console.error('Error checking user authentication:', error); | ||
// In case of an error, redirect to login as a fallback | ||
return NextResponse.redirect( | ||
new URL('/login', process.env.NEXT_PUBLIC_SITE_URL), | ||
); | ||
} | ||
|
||
if (user) { | ||
// User is logged in, redirect to dashboard | ||
return NextResponse.redirect( | ||
new URL('/dashboard', process.env.NEXT_PUBLIC_SITE_URL), | ||
); | ||
} else { | ||
// User is not logged in, redirect to login | ||
return NextResponse.redirect( | ||
new URL('/login', process.env.NEXT_PUBLIC_SITE_URL), | ||
); | ||
} | ||
} |