From e4b402d1716b2fd24cd2d6b500421ca6272c9b98 Mon Sep 17 00:00:00 2001 From: Nikita <39565703+nicitaacom@users.noreply.github.com> Date: Sat, 25 Nov 2023 08:30:11 +0100 Subject: [PATCH] +-upd: redirect to requestUrl.origin In all callback routes --- app/(auth)/auth/callback/credentials/route.ts | 6 +++--- app/(auth)/auth/callback/oauth/route.ts | 8 ++++---- app/(auth)/auth/callback/recover/route.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/(auth)/auth/callback/credentials/route.ts b/app/(auth)/auth/callback/credentials/route.ts index 072ffc5a..1268c727 100644 --- a/app/(auth)/auth/callback/credentials/route.ts +++ b/app/(auth)/auth/callback/credentials/route.ts @@ -14,7 +14,7 @@ export async function GET(request: Request) { // Redirect to error page if supabase throw error on recover const error_description = requestUrl.searchParams.get("error_description") if (error_description) { - return NextResponse.redirect(`${requestUrl.origin}error?error_description=${error_description}`) //throw error like this + return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${error_description}`) //throw error like this } /* Exchange code for cookies - update row that user confirmed email */ @@ -41,7 +41,7 @@ export async function GET(request: Request) { .single() return NextResponse.redirect( - `${requestUrl.origin}auth/completed?code=${code}?provider=credentials?userId=${response?.data.user + `${requestUrl.origin}/auth/completed?code=${code}?provider=credentials?userId=${response?.data.user .id}?username=${response.data.user.user_metadata.name || username_response?.username}?email=${ response.data.user.email }?avatarUrl=${ @@ -53,6 +53,6 @@ export async function GET(request: Request) { } } else { const error_description = encodeURIComponent("No user found after exchanging cookies for registration") - return NextResponse.redirect(`${requestUrl.origin}error?error_description=${error_description}`) + return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${error_description}`) } } diff --git a/app/(auth)/auth/callback/oauth/route.ts b/app/(auth)/auth/callback/oauth/route.ts index 5541b7eb..b4314643 100644 --- a/app/(auth)/auth/callback/oauth/route.ts +++ b/app/(auth)/auth/callback/oauth/route.ts @@ -17,7 +17,7 @@ export async function GET(request: Request) { const error_description = requestUrl.searchParams.get("error_description") if (error_description) { const supabase_error_description = encodeURIComponent(error_description) - return NextResponse.redirect(`${requestUrl.origin}error?error_description=${supabase_error_description}`) + return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${supabase_error_description}`) } if (code) { @@ -84,7 +84,7 @@ export async function GET(request: Request) { await supabaseAdmin.from("users_cart").insert({ id: response.data.user.id }) } return NextResponse.redirect( - `${requestUrl.origin}auth/completed?code=${code}&provider=${provider}&userId=${response?.data.user + `${requestUrl.origin}/auth/completed?code=${code}&provider=${provider}&userId=${response?.data.user .id}&username=${response.data.user.user_metadata.name}&email=${response.data.user.email}&avatarUrl=${ response.data.user.user_metadata.avatar_url || response.data.user?.identities![0]?.identity_data?.avatar_url || @@ -93,11 +93,11 @@ export async function GET(request: Request) { ) } else { const error_description = encodeURIComponent("No user found after exchanging cookies for registration") - return NextResponse.redirect(`${requestUrl.origin}error?error_description=${error_description}`) + return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${error_description}`) } } else { // TODO - create image on error page for this case const error_description = encodeURIComponent("No code found to exchange cookies for session") - return NextResponse.redirect(`${requestUrl.origin}error?error_description=${error_description}`) + return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${error_description}`) } } diff --git a/app/(auth)/auth/callback/recover/route.ts b/app/(auth)/auth/callback/recover/route.ts index 39e11159..67e34b8f 100644 --- a/app/(auth)/auth/callback/recover/route.ts +++ b/app/(auth)/auth/callback/recover/route.ts @@ -12,7 +12,7 @@ export async function GET(request: Request) { // 1. Redirect to error page if supabase throw error on recover const error_description = requestUrl.searchParams.get("error_description") if (error_description) { - return NextResponse.redirect(`${requestUrl.origin}error?error_description=${error_description}`) //throw error like this + return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${error_description}`) //throw error like this } if (code) { // 2. Exchange cookies to set session and get session data