Skip to content
Closed
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