@@ -53,6 +53,8 @@ import type {
5353 Web3SignatureFactor ,
5454} from '@clerk/types' ;
5555
56+ import { debugLogger } from '@/utils/debug' ;
57+
5658import {
5759 generateSignatureWithBase ,
5860 generateSignatureWithCoinbaseWallet ,
@@ -88,7 +90,7 @@ export class SignIn extends BaseResource implements SignInResource {
8890 pathRoot = '/client/sign_ins' ;
8991
9092 id ?: string ;
91- status : SignInStatus | null = null ;
93+ private _status : SignInStatus | null = null ;
9294 supportedIdentifiers : SignInIdentifier [ ] = [ ] ;
9395 supportedFirstFactors : SignInFirstFactor [ ] | null = [ ] ;
9496 supportedSecondFactors : SignInSecondFactor [ ] | null = null ;
@@ -98,6 +100,31 @@ export class SignIn extends BaseResource implements SignInResource {
98100 createdSessionId : string | null = null ;
99101 userData : UserData = new UserData ( null ) ;
100102
103+ /**
104+ * The current status of the sign-in process.
105+ *
106+ * @returns The current sign-in status, or null if no status has been set
107+ */
108+ get status ( ) : SignInStatus | null {
109+ return this . _status ;
110+ }
111+
112+ /**
113+ * Sets the sign-in status and logs the transition at debug level.
114+ *
115+ * @param value - The new status to set. Can be null to clear the status.
116+ * @remarks When setting a new status that differs from the previous one,
117+ * a debug log entry is created showing the transition from the old to new status.
118+ */
119+ set status ( value : SignInStatus | null ) {
120+ const previousStatus = this . _status ;
121+ this . _status = value ;
122+
123+ if ( value && previousStatus !== value ) {
124+ debugLogger . debug ( 'SignIn.status' , { id : this . id , from : previousStatus , to : value } ) ;
125+ }
126+ }
127+
101128 /**
102129 * @experimental This experimental API is subject to change.
103130 *
@@ -118,7 +145,8 @@ export class SignIn extends BaseResource implements SignInResource {
118145 this . fromJSON ( data ) ;
119146 }
120147
121- create = ( params : SignInCreateParams ) : Promise < this> => {
148+ create = ( params : SignInCreateParams ) : Promise < SignInResource > => {
149+ debugLogger . debug ( 'SignIn.create' , { id : this . id , strategy : 'strategy' in params ? params . strategy : undefined } ) ;
122150 return this . _basePost ( {
123151 path : this . pathRoot ,
124152 body : params ,
@@ -132,76 +160,78 @@ export class SignIn extends BaseResource implements SignInResource {
132160 } ) ;
133161 } ;
134162
135- prepareFirstFactor = ( factor : PrepareFirstFactorParams ) : Promise < SignInResource > => {
163+ prepareFirstFactor = ( params : PrepareFirstFactorParams ) : Promise < SignInResource > => {
164+ debugLogger . debug ( 'SignIn.prepareFirstFactor' , { id : this . id , strategy : params . strategy } ) ;
136165 let config ;
137- switch ( factor . strategy ) {
166+ switch ( params . strategy ) {
138167 case 'passkey' :
139168 config = { } as PassKeyConfig ;
140169 break ;
141170 case 'email_link' :
142171 config = {
143- emailAddressId : factor . emailAddressId ,
144- redirectUrl : factor . redirectUrl ,
172+ emailAddressId : params . emailAddressId ,
173+ redirectUrl : params . redirectUrl ,
145174 } as EmailLinkConfig ;
146175 break ;
147176 case 'email_code' :
148- config = { emailAddressId : factor . emailAddressId } as EmailCodeConfig ;
177+ config = { emailAddressId : params . emailAddressId } as EmailCodeConfig ;
149178 break ;
150179 case 'phone_code' :
151180 config = {
152- phoneNumberId : factor . phoneNumberId ,
153- default : factor . default ,
154- channel : factor . channel ,
181+ phoneNumberId : params . phoneNumberId ,
182+ default : params . default ,
183+ channel : params . channel ,
155184 } as PhoneCodeConfig ;
156185 break ;
157186 case 'web3_metamask_signature' :
158187 case 'web3_base_signature' :
159188 case 'web3_coinbase_wallet_signature' :
160189 case 'web3_okx_wallet_signature' :
161- config = { web3WalletId : factor . web3WalletId } as Web3SignatureConfig ;
190+ config = { web3WalletId : params . web3WalletId } as Web3SignatureConfig ;
162191 break ;
163192 case 'reset_password_phone_code' :
164- config = { phoneNumberId : factor . phoneNumberId } as ResetPasswordPhoneCodeFactorConfig ;
193+ config = { phoneNumberId : params . phoneNumberId } as ResetPasswordPhoneCodeFactorConfig ;
165194 break ;
166195 case 'reset_password_email_code' :
167- config = { emailAddressId : factor . emailAddressId } as ResetPasswordEmailCodeFactorConfig ;
196+ config = { emailAddressId : params . emailAddressId } as ResetPasswordEmailCodeFactorConfig ;
168197 break ;
169198 case 'saml' :
170199 config = {
171- redirectUrl : factor . redirectUrl ,
172- actionCompleteRedirectUrl : factor . actionCompleteRedirectUrl ,
200+ redirectUrl : params . redirectUrl ,
201+ actionCompleteRedirectUrl : params . actionCompleteRedirectUrl ,
173202 } as SamlConfig ;
174203 break ;
175204 case 'enterprise_sso' :
176205 config = {
177- redirectUrl : factor . redirectUrl ,
178- actionCompleteRedirectUrl : factor . actionCompleteRedirectUrl ,
179- oidcPrompt : factor . oidcPrompt ,
206+ redirectUrl : params . redirectUrl ,
207+ actionCompleteRedirectUrl : params . actionCompleteRedirectUrl ,
208+ oidcPrompt : params . oidcPrompt ,
180209 } as EnterpriseSSOConfig ;
181210 break ;
182211 default :
183- clerkInvalidStrategy ( 'SignIn.prepareFirstFactor' , factor . strategy ) ;
212+ clerkInvalidStrategy ( 'SignIn.prepareFirstFactor' , params . strategy ) ;
184213 }
185214 return this . _basePost ( {
186- body : { ...config , strategy : factor . strategy } ,
215+ body : { ...config , strategy : params . strategy } ,
187216 action : 'prepare_first_factor' ,
188217 } ) ;
189218 } ;
190219
191- attemptFirstFactor = ( attemptFactor : AttemptFirstFactorParams ) : Promise < SignInResource > => {
220+ attemptFirstFactor = ( params : AttemptFirstFactorParams ) : Promise < SignInResource > => {
221+ debugLogger . debug ( 'SignIn.attemptFirstFactor' , { id : this . id , strategy : params . strategy } ) ;
192222 let config ;
193- switch ( attemptFactor . strategy ) {
223+ switch ( params . strategy ) {
194224 case 'passkey' :
195225 config = {
196- publicKeyCredential : JSON . stringify ( serializePublicKeyCredentialAssertion ( attemptFactor . publicKeyCredential ) ) ,
226+ publicKeyCredential : JSON . stringify ( serializePublicKeyCredentialAssertion ( params . publicKeyCredential ) ) ,
197227 } ;
198228 break ;
199229 default :
200- config = { ...attemptFactor } ;
230+ config = { ...params } ;
201231 }
202232
203233 return this . _basePost ( {
204- body : { ...config , strategy : attemptFactor . strategy } ,
234+ body : { ...config , strategy : params . strategy } ,
205235 action : 'attempt_first_factor' ,
206236 } ) ;
207237 } ;
@@ -243,13 +273,15 @@ export class SignIn extends BaseResource implements SignInResource {
243273 } ;
244274
245275 prepareSecondFactor = ( params : PrepareSecondFactorParams ) : Promise < SignInResource > => {
276+ debugLogger . debug ( 'SignIn.prepareSecondFactor' , { id : this . id , strategy : params . strategy } ) ;
246277 return this . _basePost ( {
247278 body : params ,
248279 action : 'prepare_second_factor' ,
249280 } ) ;
250281 } ;
251282
252283 attemptSecondFactor = ( params : AttemptSecondFactorParams ) : Promise < SignInResource > => {
284+ debugLogger . debug ( 'SignIn.attemptSecondFactor' , { id : this . id , strategy : params . strategy } ) ;
253285 return this . _basePost ( {
254286 body : params ,
255287 action : 'attempt_second_factor' ,
0 commit comments