TypeError in exchangeCodeForSession upon email verification callback
Hello everyone! Appreciate your time to help me!
I'm using @supabase/ssr library in my NextJS application, everything works except the email verification flow which triggers the email that contains the following link (which looks correct):
http://localhost:3000/auth/callback?code=545dd806-6358-43e0-a88b-9a1bcb56adaa
Error:
/app/auth/callback/route.js
Anyone an idea what goes wrong?
Thanks.
I'm using @supabase/ssr library in my NextJS application, everything works except the email verification flow which triggers the email that contains the following link (which looks correct):
http://localhost:3000/auth/callback?code=545dd806-6358-43e0-a88b-9a1bcb56adaa
Error:
TypeError: Cannot read properties of null (reading 'split')
at SupabaseAuthClient._exchangeCodeForSession (webpack-internal:///(rsc)/./node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.js:402:163)/app/auth/callback/route.js
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';
import { createServerClient } from '@supabase/ssr';
export async function GET(request) {
const { searchParams, origin } = new URL(request.url);
console.log(searchParams);
console.log(origin);
const code = searchParams.get('code');
const next = searchParams.get('next') ?? '/';
if (code) {
const cookieStore = cookies()
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
{
cookies: {
get(name) {
return cookieStore.get(name)?.value
},
set(name, value, options) {
cookieStore.set({ name, value, ...options })
},
remove(name, options) {
cookieStore.delete({ name, ...options })
},
},
}
)
const { error } = await supabase.auth.exchangeCodeForSession(code)
if (!error) {
return NextResponse.redirect(${origin}${next})
}
}
return NextResponse.redirect(${origin}/auth/auth-code-error)
}
Anyone an idea what goes wrong?
Thanks.