@@ -103,10 +103,10 @@ class Auth {
103103 bool get isSignedIn => user != null ;
104104
105105 /// Are we currently signing in?
106- bool get isSigningIn => signIn? .status.isActive == true ;
106+ bool get isSigningIn => signIn != null ;
107107
108108 /// Are we currently signing up?
109- bool get isSigningUp => signUp? .status.isActive == true ;
109+ bool get isSigningUp => signUp != null ;
110110
111111 /// A method to be overridden by extension classes to cope with
112112 /// updating their systems when things change (e.g. the clerk_flutter
@@ -236,6 +236,13 @@ class Auth {
236236 update ();
237237 }
238238
239+ /// Reset the current [Client] : clear any [SignUp] or [SignIn] object
240+ ///
241+ Future <void > resetClient () async {
242+ client = await _api.resetClient ();
243+ update ();
244+ }
245+
239246 /// Refresh the current [Environment]
240247 ///
241248 Future <void > refreshEnvironment () async {
@@ -283,12 +290,17 @@ class Auth {
283290 Future <void > oauthSignIn ({
284291 required Strategy strategy,
285292 required Uri ? redirect,
293+ String ? identifier,
286294 }) async {
287295 final redirectUrl = redirect? .toString () ?? ClerkConstants .oauthRedirect;
288296 await _api
289- .createSignIn (strategy: strategy, redirectUrl: redirectUrl)
297+ .createSignIn (
298+ strategy: strategy,
299+ identifier: identifier,
300+ redirectUrl: redirectUrl,
301+ )
290302 .then (_housekeeping);
291- if (client.signIn case SignIn signIn) {
303+ if (client.signIn case SignIn signIn when signIn.hasVerification == false ) {
292304 await _api
293305 .prepareSignIn (
294306 signIn,
@@ -363,8 +375,10 @@ class Auth {
363375 return ;
364376 }
365377
366- // Ensure we have a signIn object
367- if (client.signIn == null ) {
378+ // Ensure we have a signIn object for the current identifier
379+ if (client.signIn == null ||
380+ (identifier? .orNullIfEmpty is String &&
381+ identifier != client.signIn! .identifier)) {
368382 // if password and identifier been presented, we can immediately attempt
369383 // a sign in; if null they will be ignored
370384 await _api
@@ -377,22 +391,14 @@ class Auth {
377391 // We have signed in - possibly when creating the [SignIn] above
378392 break ;
379393
380- case SignIn signIn
381- when signIn.status == Status .needsIdentifier && identifier is String :
382- // if a password has been presented, we can immediately attempt a
383- // sign in; if `password` is null it will be ignored
384- await _api
385- .createSignIn (identifier: identifier, password: password)
386- .then (_housekeeping);
387-
388- case SignIn signIn when strategy.isOauth && token is String :
394+ case SignIn signIn when strategy.isSSO && token is String :
389395 await _api
390396 .sendOauthToken (signIn, strategy: strategy, token: token)
391397 .then (_housekeeping);
392398
393399 case SignIn signIn
394400 when strategy.isPasswordResetter &&
395- code is String &&
401+ code? .length == _codeLength &&
396402 password is String :
397403 await _api
398404 .attemptSignIn (
@@ -431,13 +437,13 @@ class Auth {
431437 return signInCompleter.future;
432438
433439 case SignIn signIn
434- when signIn.status == Status .needsFirstFactor &&
435- strategy == Strategy .password &&
440+ when signIn.status.needsFactor &&
441+ strategy.isPassword &&
436442 password is String :
437443 await _api
438444 .attemptSignIn (
439445 signIn,
440- stage: Stage .first ,
446+ stage: Stage .forStatus (signIn.status) ,
441447 strategy: Strategy .password,
442448 password: password,
443449 )
@@ -459,26 +465,6 @@ class Auth {
459465 stage: stage, strategy: strategy, code: code)
460466 .then (_housekeeping);
461467 }
462-
463- case SignIn signIn when signIn.status.needsFactor:
464- final stage = Stage .forStatus (signIn.status);
465- await _api
466- .prepareSignIn (signIn, stage: stage, strategy: strategy)
467- .then (_housekeeping);
468- await _api
469- .attemptSignIn (signIn, stage: stage, strategy: strategy, code: code)
470- .then (_housekeeping);
471-
472- // No matching sign-in sequence, reset loading state
473- default :
474- final status = signIn? .status ?? Status .unknown;
475- addError (
476- AuthError (
477- code: AuthErrorCode .signInError,
478- message: 'Unsupported sign in attempt: {arg}' ,
479- argument: status.name,
480- ),
481- );
482468 }
483469
484470 update ();
0 commit comments