-
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.
- Loading branch information
Showing
6 changed files
with
350 additions
and
302 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/app/(dynamic-pages)/(login-pages)/auth/sso-verify/page.tsx
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,31 @@ | ||
|
||
'use client' | ||
|
||
import { supabaseAnonClient } from '@/supabase-clients/anon/supabaseAnonClient'; | ||
import { AuthChangeEvent, Session } from "@supabase/supabase-js"; | ||
import { useEffect, useState } from "react"; | ||
|
||
|
||
export default function Default() { | ||
const supabase = supabaseAnonClient; | ||
|
||
const [authState, setAuthState] = useState<AuthChangeEvent | "">(""); | ||
const [session, setSession] = useState<Session | null>(null); | ||
|
||
useEffect(() => { | ||
supabase.auth.onAuthStateChange((event, sessionValue) => { | ||
console.log('state change', event, sessionValue) | ||
if (event === "INITIAL_SESSION") { | ||
window.location.href = `/auth/callback-tokens?access_token=${sessionValue?.access_token}&refresh_token=${sessionValue?.refresh_token}` | ||
} else { | ||
setAuthState(event); | ||
} | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<p>Verifying login ...</p> | ||
</> | ||
); | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createSupabaseUserRouteHandlerClient } from '@/supabase-clients/user/createSupabaseUserRouteHandlerClient'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function GET() { | ||
if (process.env.NEXT_PUBLIC_SSO_DOMAIN !== undefined) { | ||
return NextResponse.redirect( | ||
new URL('/auth/sso-verify', process.env.NEXT_PUBLIC_SITE_URL), | ||
); | ||
} | ||
|
||
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), | ||
); | ||
} | ||
} |
Oops, something went wrong.