Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handling non success status codes on "/verify" call #1100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading