@@ -497,12 +497,82 @@ class SignInFuture implements SignInFutureResource {
497
497
verifyCode : this . verifyEmailCode . bind ( this ) ,
498
498
} ;
499
499
500
+ resetPasswordEmailCode = {
501
+ sendCode : this . sendResetPasswordEmailCode . bind ( this ) ,
502
+ verifyCode : this . verifyResetPasswordEmailCode . bind ( this ) ,
503
+ submitPassword : this . submitResetPassword . bind ( this ) ,
504
+ } ;
505
+
500
506
constructor ( readonly resource : SignIn ) { }
501
507
502
508
get status ( ) {
503
509
return this . resource . status ;
504
510
}
505
511
512
+ async sendResetPasswordEmailCode ( ) : Promise < { error : unknown } > {
513
+ eventBus . emit ( 'resource:error' , { resource : this . resource , error : null } ) ;
514
+ try {
515
+ if ( ! this . resource . id ) {
516
+ throw new Error ( 'Cannot reset password without a sign in.' ) ;
517
+ }
518
+
519
+ const resetPasswordEmailCodeFactor = this . resource . supportedFirstFactors ?. find (
520
+ f => f . strategy === 'reset_password_email_code' ,
521
+ ) ;
522
+
523
+ if ( ! resetPasswordEmailCodeFactor ) {
524
+ throw new Error ( 'Reset password email code factor not found' ) ;
525
+ }
526
+
527
+ const { emailAddressId } = resetPasswordEmailCodeFactor ;
528
+ await this . resource . __internal_basePost ( {
529
+ body : { emailAddressId, strategy : 'reset_password_email_code' } ,
530
+ action : 'prepare_first_factor' ,
531
+ } ) ;
532
+ } catch ( err : unknown ) {
533
+ eventBus . emit ( 'resource:error' , { resource : this . resource , error : err } ) ;
534
+ return { error : err } ;
535
+ }
536
+
537
+ return { error : null } ;
538
+ }
539
+
540
+ async verifyResetPasswordEmailCode ( { code } : { code : string } ) : Promise < { error : unknown } > {
541
+ eventBus . emit ( 'resource:error' , { resource : this . resource , error : null } ) ;
542
+ try {
543
+ await this . resource . __internal_basePost ( {
544
+ body : { code, strategy : 'reset_password_email_code' } ,
545
+ action : 'attempt_first_factor' ,
546
+ } ) ;
547
+ } catch ( err : unknown ) {
548
+ eventBus . emit ( 'resource:error' , { resource : this . resource , error : err } ) ;
549
+ return { error : err } ;
550
+ }
551
+
552
+ return { error : null } ;
553
+ }
554
+
555
+ async submitResetPassword ( {
556
+ password,
557
+ signOutOfOtherSessions = true ,
558
+ } : {
559
+ password : string ;
560
+ signOutOfOtherSessions ?: boolean ;
561
+ } ) : Promise < { error : unknown } > {
562
+ eventBus . emit ( 'resource:error' , { resource : this . resource , error : null } ) ;
563
+ try {
564
+ await this . resource . __internal_basePost ( {
565
+ body : { password, signOutOfOtherSessions } ,
566
+ action : 'reset_password' ,
567
+ } ) ;
568
+ } catch ( err : unknown ) {
569
+ eventBus . emit ( 'resource:error' , { resource : this . resource , error : err } ) ;
570
+ return { error : err } ;
571
+ }
572
+
573
+ return { error : null } ;
574
+ }
575
+
506
576
async create ( params : {
507
577
identifier ?: string ;
508
578
strategy ?: OAuthStrategy | 'saml' | 'enterprise_sso' ;
0 commit comments