File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ export default async function ResetPasswordPage({ searchParams }: ResetPasswordP
1616 const code = params . code ;
1717 const error = params . error ;
1818
19+ // If there's a code, redirect to the route handler to exchange it
20+ // This ensures cookies are properly set
21+ if ( code ) {
22+ redirect ( `/auth/reset-password?code=${ code } ` ) ;
23+ }
24+
1925 // If there's an error from the callback
2026 if ( error ) {
2127 return (
@@ -43,27 +49,6 @@ export default async function ResetPasswordPage({ searchParams }: ResetPasswordP
4349
4450 const supabase = await createClient ( ) ;
4551
46- // If there's a code, exchange it for a session
47- if ( code ) {
48- const { error : exchangeError } = await supabase . auth . exchangeCodeForSession ( code ) ;
49-
50- if ( exchangeError ) {
51- console . error ( 'Code exchange error:' , exchangeError ) ;
52- redirect ( '/reset-password?error=invalid_code' ) ;
53- }
54-
55- // Code exchanged successfully - show the form directly without redirect
56- return (
57- < div className = "rounded-xl border border-gray-200 bg-white p-8 shadow-sm" >
58- < div className = "mb-8 text-center" >
59- < h1 className = "text-2xl font-bold text-gray-900" > Reset your password</ h1 >
60- < p className = "mt-2 text-sm text-gray-600" > Enter your new password below</ p >
61- </ div >
62- < ResetPasswordForm />
63- </ div >
64- ) ;
65- }
66-
6752 // Check if user has an active session (required to update password)
6853 const { data : { user } } = await supabase . auth . getUser ( ) ;
6954
Original file line number Diff line number Diff line change 1+ import { createClient } from '@/lib/supabase/server' ;
2+ import { NextResponse } from 'next/server' ;
3+
4+ export async function GET ( request : Request ) {
5+ const { searchParams, origin } = new URL ( request . url ) ;
6+ const code = searchParams . get ( 'code' ) ;
7+
8+ if ( code ) {
9+ const supabase = await createClient ( ) ;
10+ const { error } = await supabase . auth . exchangeCodeForSession ( code ) ;
11+
12+ if ( ! error ) {
13+ // Session established, redirect to reset password form
14+ return NextResponse . redirect ( `${ origin } /reset-password` ) ;
15+ }
16+
17+ console . error ( 'Password reset code exchange error:' , error ) ;
18+ }
19+
20+ // Return to reset password page with error
21+ return NextResponse . redirect ( `${ origin } /reset-password?error=invalid_code` ) ;
22+ }
You can’t perform that action at this time.
0 commit comments