Skip to content

Commit

Permalink
- Handling non success status codes on "/verify" call
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvesh-dalvi-1 committed Dec 13, 2024
1 parent ccfcbf5 commit f73ae74
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions packages/gotrue/lib/src/gotrue_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -538,33 +538,38 @@ class GoTrueClient {
assert(token != null || tokenHash != null,
'`token` or `tokenHash` needs to be specified.');

final body = {
if (email != null) 'email': email,
if (phone != null) 'phone': phone,
if (token != null) 'token': token,
'type': type.snakeCase,
'redirect_to': redirectTo,
'gotrue_meta_security': {'captchaToken': captchaToken},
if (tokenHash != null) 'token_hash': tokenHash,
};
final fetchOptions = GotrueRequestOptions(headers: _headers, body: body);
final response = await _fetch
.request('$_url/verify', RequestMethodType.post, options: fetchOptions);
try {
final body = {
if (email != null) 'email': email,
if (phone != null) 'phone': phone,
if (token != null) 'token': token,
'type': type.snakeCase,
'redirect_to': redirectTo,
'gotrue_meta_security': {'captchaToken': captchaToken},
if (tokenHash != null) 'token_hash': tokenHash,
};
final fetchOptions = GotrueRequestOptions(headers: _headers, body: body);
final response = await _fetch.request(
'$_url/verify', RequestMethodType.post,
options: fetchOptions);

final authResponse = AuthResponse.fromJson(response);
final authResponse = AuthResponse.fromJson(response);

if (authResponse.session == null) {
throw AuthException(
'An error occurred on token verification.',
);
}
if (authResponse.session == null) {
throw AuthException(
'An error occurred on token verification.',
);
}

_saveSession(authResponse.session!);
notifyAllSubscribers(type == OtpType.recovery
? AuthChangeEvent.passwordRecovery
: AuthChangeEvent.signedIn);
_saveSession(authResponse.session!);
notifyAllSubscribers(type == OtpType.recovery
? AuthChangeEvent.passwordRecovery
: AuthChangeEvent.signedIn);

return authResponse;
return authResponse;
} catch (e) {
return AuthResponse(session: null, user: null);
}
}

/// Obtains a URL to perform a single-sign on using an enterprise Identity
Expand Down

0 comments on commit f73ae74

Please sign in to comment.