@@ -32,14 +32,14 @@ const AuthLayout = ({ children }: AuthLayoutProps) => (
3232 </ div >
3333) ;
3434
35- const InputField = ( { icon : Icon , ...props } : InputFieldProps ) => (
35+ const InputField = ( { icon : Icon , className , ...props } : InputFieldProps ) => (
3636 < div className = "relative" >
3737 < div className = "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none" >
3838 < Icon className = "h-5 w-5 text-gray-400" />
3939 </ div >
4040 < input
41- { ...props }
42- className = " block w-full pl-10 pr-3 py-2 border border-gray-800 rounded-lg bg-gray-900 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"
41+ { ...props }
42+ className = { ` block w-full pl-10 pr-3 py-2 border border-gray-800 rounded-lg bg-gray-900 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent ${ className ?? '' } ` }
4343 />
4444 </ div >
4545) ;
@@ -53,15 +53,16 @@ export default function ResetPasswordPage() {
5353
5454
5555 useEffect ( ( ) => {
56- const params = new URLSearchParams ( window . location . hash . slice ( 1 ) ) ;
56+ const paramsHash = new URLSearchParams ( window . location . hash . slice ( 1 ) ) ;
57+ const paramsSearch = new URLSearchParams ( window . location . search ) ;
5758
58- const accessToken = params . get ( 'access_token' ) ;
59- const refreshToken = params . get ( 'refresh_token' ) ;
59+ const accessToken = paramsHash . get ( 'access_token' ) ;
60+ const refreshToken = paramsHash . get ( 'refresh_token' ) ;
61+ const code = paramsSearch . get ( 'code' ) ;
6062
61- const clearUrlHash = ( ) => {
62- if ( window . location . hash ) {
63- window . history . replaceState ( { } , document . title , window . location . pathname + window . location . search ) ;
64- }
63+ const clearUrl = ( ) => {
64+ const url = window . location . pathname ;
65+ window . history . replaceState ( { } , document . title , url ) ;
6566 } ;
6667
6768 if ( accessToken && refreshToken ) {
@@ -79,17 +80,33 @@ export default function ResetPasswordPage() {
7980 toast . error ( "Error setting session" ) ;
8081 navigate ( '/login' , { replace : true } ) ;
8182 } finally {
82- clearUrlHash ( ) ;
83+ clearUrl ( ) ;
84+ }
85+ } ) ( ) ;
86+ } else if ( code ) {
87+ ( async ( ) => {
88+ try {
89+ const { error } = await supabase . auth . exchangeCodeForSession ( code ) ;
90+ if ( error ) {
91+ toast . error ( "Error exchanging code: " + error . message ) ;
92+ navigate ( '/login' , { replace : true } ) ;
93+ }
94+ } catch {
95+ toast . error ( "Error exchanging code" ) ;
96+ navigate ( '/login' , { replace : true } ) ;
97+ } finally {
98+ clearUrl ( ) ;
8399 }
84100 } ) ( ) ;
85101 } else {
86102 toast . error ( "Access denied" ) ;
87103 navigate ( '/login' , { replace : true } ) ;
88- clearUrlHash ( ) ;
104+ clearUrl ( ) ;
89105 }
90106 } , [ navigate ] ) ;
91107
92108
109+
93110 const handleAuth = async ( e : FormEvent < HTMLFormElement > ) => {
94111 e . preventDefault ( ) ;
95112 const formData = new FormData ( e . currentTarget ) ;
0 commit comments