@@ -55,7 +55,11 @@ import {
5555 getOKXWalletIdentifier ,
5656 windowNavigate ,
5757} from '../../utils' ;
58- import { _authenticateWithPopup } from '../../utils/authenticateWithPopup' ;
58+ import {
59+ _authenticateWithPopup ,
60+ _futureAuthenticateWithPopup ,
61+ wrapWithPopupRoutes ,
62+ } from '../../utils/authenticateWithPopup' ;
5963import { CaptchaChallenge } from '../../utils/captcha/CaptchaChallenge' ;
6064import { createValidatePassword } from '../../utils/passwords/password' ;
6165import { normalizeUnsafeMetadata } from '../../utils/resourceParams' ;
@@ -789,7 +793,17 @@ class SignUpFuture implements SignUpFutureResource {
789793 }
790794
791795 async sso ( params : SignUpFutureSSOParams ) : Promise < { error : ClerkError | null } > {
792- const { strategy, redirectUrl, redirectCallbackUrl } = params ;
796+ const {
797+ strategy,
798+ redirectUrl,
799+ redirectCallbackUrl,
800+ unsafeMetadata,
801+ legalAccepted,
802+ oidcPrompt,
803+ enterpriseConnectionId,
804+ emailAddress,
805+ popup,
806+ } = params ;
793807 return runAsyncResourceTask ( this . resource , async ( ) => {
794808 const { captchaToken, captchaWidgetType, captchaError } = await this . getCaptchaToken ( ) ;
795809
@@ -800,24 +814,56 @@ class SignUpFuture implements SignUpFutureResource {
800814 redirectUrlComplete = window . location . origin + redirectUrl ;
801815 }
802816
803- await this . resource . __internal_basePost ( {
804- path : this . resource . pathRoot ,
805- body : {
806- strategy,
807- redirectUrl : SignUp . clerk . buildUrlWithAuth ( redirectCallbackUrl ) ,
808- redirectUrlComplete,
809- captchaToken,
810- captchaWidgetType,
811- captchaError,
812- } ,
817+ const routes = {
818+ redirectUrl : SignUp . clerk . buildUrlWithAuth ( redirectCallbackUrl ) ,
819+ actionCompleteRedirectUrl : redirectUrlComplete ,
820+ } ;
821+ if ( popup ) {
822+ const wrappedRoutes = wrapWithPopupRoutes ( SignUp . clerk , {
823+ redirectCallbackUrl : routes . redirectUrl ,
824+ redirectUrl : redirectUrlComplete ,
825+ } ) ;
826+ routes . redirectUrl = wrappedRoutes . redirectCallbackUrl ;
827+ routes . actionCompleteRedirectUrl = wrappedRoutes . redirectUrl ;
828+ }
829+
830+ const authenticateFn = ( ) => {
831+ return this . resource . __internal_basePost ( {
832+ path : this . resource . pathRoot ,
833+ body : {
834+ strategy,
835+ ...routes ,
836+ unsafeMetadata,
837+ legalAccepted,
838+ oidcPrompt,
839+ enterpriseConnectionId,
840+ emailAddress,
841+ captchaToken,
842+ captchaWidgetType,
843+ captchaError,
844+ } ,
845+ } ) ;
846+ } ;
847+
848+ await authenticateFn ( ) . catch ( async e => {
849+ if ( isClerkAPIResponseError ( e ) && isCaptchaError ( e ) ) {
850+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
851+ await SignUp . clerk . __unstable__environment ! . reload ( ) ;
852+ return authenticateFn ( ) ;
853+ }
854+ throw e ;
813855 } ) ;
814856
815857 const { status, externalVerificationRedirectURL } = this . resource . verifications . externalAccount ;
816858
817- if ( status === 'unverified' && ! ! externalVerificationRedirectURL ) {
818- windowNavigate ( externalVerificationRedirectURL ) ;
819- } else {
820- clerkInvalidFAPIResponse ( status , SignUp . fapiClient . buildEmailAddress ( 'support' ) ) ;
859+ if ( status === 'unverified' && externalVerificationRedirectURL ) {
860+ if ( popup ) {
861+ await _futureAuthenticateWithPopup ( SignUp . clerk , { popup, externalVerificationRedirectURL } ) ;
862+ // Pick up the modified SignUp resource
863+ await this . resource . reload ( ) ;
864+ } else {
865+ windowNavigate ( externalVerificationRedirectURL ) ;
866+ }
821867 }
822868 } ) ;
823869 }
0 commit comments