@@ -358,10 +358,15 @@ export class NextAppAuth extends NextAuth {
358358 [ "email" ] ,
359359 "email missing from request body"
360360 ) ;
361- ( await this . core ) . sendPasswordResetEmail (
362- email ,
363- this . options . passwordResetUrl
364- ) ;
361+ const { verifier } = await (
362+ await this . core
363+ ) . sendPasswordResetEmail ( email , this . options . passwordResetUrl ) ;
364+ cookies ( ) . set ( {
365+ name : this . options . pkceVerifierCookieName ,
366+ value : verifier ,
367+ httpOnly : true ,
368+ sameSite : "strict" ,
369+ } ) ;
365370 return new Response ( null , { status : 204 } ) ;
366371 }
367372 case "emailpassword/reset-password" : {
@@ -372,6 +377,14 @@ export class NextAppAuth extends NextAuth {
372377 }
373378 let tokenData : TokenData ;
374379 try {
380+ const verifier = req . cookies . get (
381+ this . options . pkceVerifierCookieName
382+ ) ?. value ;
383+ if ( ! verifier ) {
384+ return onEmailPasswordReset ( {
385+ error : new Error ( "no pkce verifier cookie found" ) ,
386+ } ) ;
387+ }
375388 const [ resetToken , password ] = _extractParams (
376389 await _getReqBody ( req ) ,
377390 [ "reset_token" , "password" ] ,
@@ -380,7 +393,7 @@ export class NextAppAuth extends NextAuth {
380393
381394 tokenData = await (
382395 await this . core
383- ) . resetPasswordWithResetToken ( resetToken , password ) ;
396+ ) . resetPasswordWithResetToken ( resetToken , verifier , password ) ;
384397 } catch ( err ) {
385398 return onEmailPasswordReset ( {
386399 error : err instanceof Error ? err : new Error ( String ( err ) ) ,
@@ -392,6 +405,7 @@ export class NextAppAuth extends NextAuth {
392405 httpOnly : true ,
393406 sameSite : "strict" ,
394407 } ) ;
408+ cookies ( ) . delete ( this . options . pkceVerifierCookieName ) ;
395409 return onEmailPasswordReset ( { error : null , tokenData } ) ;
396410 }
397411 case "emailpassword/resend-verification-email" : {
@@ -476,30 +490,43 @@ export class NextAppAuth extends NextAuth {
476490 throw new Error ( `'passwordResetUrl' option not configured` ) ;
477491 }
478492 const [ email ] = _extractParams ( data , [ "email" ] , "email missing" ) ;
479- await (
493+ const { verifier } = await (
480494 await this . core
481495 ) . sendPasswordResetEmail (
482496 email ,
483497 `${ this . options . baseUrl } /${ this . options . passwordResetUrl } `
484498 ) ;
499+ cookies ( ) . set ( {
500+ name : this . options . pkceVerifierCookieName ,
501+ value : verifier ,
502+ httpOnly : true ,
503+ sameSite : "strict" ,
504+ } ) ;
485505 } ,
486506 emailPasswordResetPassword : async (
487507 data : FormData | { resetToken : string ; password : string }
488508 ) => {
509+ const verifier = cookies ( ) . get (
510+ this . options . pkceVerifierCookieName
511+ ) ?. value ;
512+ if ( ! verifier ) {
513+ throw new Error ( "no pkce verifier cookie found" ) ;
514+ }
489515 const [ resetToken , password ] = _extractParams (
490516 data ,
491517 [ "reset_token" , "password" ] ,
492518 "reset_token or password missing"
493519 ) ;
494520 const tokenData = await (
495521 await this . core
496- ) . resetPasswordWithResetToken ( resetToken , password ) ;
522+ ) . resetPasswordWithResetToken ( resetToken , verifier , password ) ;
497523 cookies ( ) . set ( {
498524 name : this . options . authCookieName ,
499525 value : tokenData . auth_token ,
500526 httpOnly : true ,
501527 sameSite : "strict" ,
502528 } ) ;
529+ cookies ( ) . delete ( this . options . pkceVerifierCookieName ) ;
503530 return tokenData ;
504531 } ,
505532 emailPasswordResendVerificationEmail : async (
0 commit comments