diff --git a/apps/docs/pages/guides/auth/server-side/email-based-auth-with-pkce-flow-for-ssr.mdx b/apps/docs/pages/guides/auth/server-side/email-based-auth-with-pkce-flow-for-ssr.mdx index 88afb95dc41..0eea3cf2723 100644 --- a/apps/docs/pages/guides/auth/server-side/email-based-auth-with-pkce-flow-for-ssr.mdx +++ b/apps/docs/pages/guides/auth/server-side/email-based-auth-with-pkce-flow-for-ssr.mdx @@ -31,13 +31,15 @@ Create a new file at `app/auth/confirm/route.ts` and populate with the following import { createServerClient, type CookieOptions } from '@supabase/ssr' import { type EmailOtpType } from '@supabase/supabase-js' import { cookies } from 'next/headers' -import { NextResponse } from 'next/server' +import { NextRequest, NextResponse } from 'next/server' -export async function GET(request: Request) { +export async function GET(request: NextRequest) { const { searchParams } = new URL(request.url) const token_hash = searchParams.get('token_hash') const type = searchParams.get('type') as EmailOtpType | null const next = searchParams.get('next') ?? '/' + const redirectTo = request.nextUrl.clone() + redirectTo.pathname = next if (token_hash && type) { const cookieStore = cookies() @@ -64,12 +66,13 @@ export async function GET(request: Request) { token_hash, }) if (!error) { - return NextResponse.redirect(next) + return NextResponse.redirect(redirectTo) } } // return the user to an error page with some instructions - return NextResponse.redirect('/auth/auth-code-error') + redirectTo.pathname = '/auth/auth-code-error' + return NextResponse.redirect(redirectTo) } ```