Skip to content

Commit

Permalink
+-upd: redirect to requestUrl.origin
Browse files Browse the repository at this point in the history
In all callback routes
  • Loading branch information
nicitaacom committed Nov 25, 2023
1 parent cece89f commit e4b402d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/(auth)/auth/callback/credentials/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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=${
Expand All @@ -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}`)
}
}
8 changes: 4 additions & 4 deletions app/(auth)/auth/callback/oauth/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ||
Expand All @@ -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}`)
}
}
2 changes: 1 addition & 1 deletion app/(auth)/auth/callback/recover/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e4b402d

Please sign in to comment.