SupabaseS
Supabase6mo ago
Abdul

resetPasswordForEmail not respecting the redirectURL

Hi, for some reason when using supabsae.auth.resetPasswordForEmail(), it's ignoring the redirectURL and just redirecting to the home page of my application, here's my code:
        const { error } = await supabase.auth.resetPasswordForEmail(email, {
          redirectTo: `${getBaseUrl()}/reset-password`,
        });


callback/route.ts (not sure if applicable):
export async function GET(request: Request) {
  const { searchParams, origin } = new URL(request.url)
  const code = searchParams.get('code')
  const next = searchParams.get('next') || '/'

  if (code) {
    const cookieStore = await cookies()
    const supabase = createServerClient(
      process.env.NEXT_PUBLIC_SUPABASE_URL!,
      process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
      {
        cookies: {
          getAll() {
            return cookieStore.getAll()
          },
          setAll(cookiesToSet) {
            cookiesToSet.forEach(({ name, value, options }) => {
              cookieStore.set(name, value, options)
            })
          },
        },
      }
    )

    const { error } = await supabase.auth.exchangeCodeForSession(code)
    
    if (!error) {
      return NextResponse.redirect(`${origin}${next}`)
    }
  }

  // Return the user to an error page with instructions
  return NextResponse.redirect(`${origin}/auth/auth-error`)
}


Clicking the password reset link in the email is structured like this:
https://xxxxx.supabase.co/auth/v1/verify?token=pkce_.....&type=recovery&redirect_to=https://peershare.co.uk as you can see, /reset-password is not included in the link. What can I do?
Was this page helpful?