@@ -518,17 +518,28 @@ class GoTrueClient {
518518 String ? captchaToken,
519519 String ? tokenHash,
520520 }) async {
521- assert (
522- ((email != null && phone == null ) ||
523- (email == null && phone != null )) ||
524- (tokenHash != null ),
525- '`email` or `phone` needs to be specified.' );
526- assert (token != null || tokenHash != null ,
527- '`token` or `tokenHash` needs to be specified.' );
521+ // For recovery type with tokenHash, only tokenHash and type are required
522+ final isRecoveryWithTokenHash =
523+ type == OtpType .recovery && tokenHash != null ;
524+
525+ if (! isRecoveryWithTokenHash) {
526+ assert (
527+ ((email != null && phone == null ) ||
528+ (email == null && phone != null )) ||
529+ (tokenHash != null ),
530+ '`email` or `phone` needs to be specified.' );
531+ assert (token != null || tokenHash != null ,
532+ '`token` or `tokenHash` needs to be specified.' );
533+ } else {
534+ // For recovery with tokenHash, email/phone should not be provided
535+ assert (email == null && phone == null ,
536+ 'For recovery type with tokenHash, only tokenHash and type should be provided.' );
537+ }
528538
529539 final body = {
530- if (email != null ) 'email' : email,
531- if (phone != null ) 'phone' : phone,
540+ // For recovery type with tokenHash, exclude email/phone
541+ if (! isRecoveryWithTokenHash && email != null ) 'email' : email,
542+ if (! isRecoveryWithTokenHash && phone != null ) 'phone' : phone,
532543 if (token != null ) 'token' : token,
533544 'type' : type.snakeCase,
534545 'redirect_to' : redirectTo,
0 commit comments