signInWithEmail method
Future<GotrueSessionResponse>
signInWithEmail(
- String email,
- String password, {
- AuthOptions? options,
Logs in an existing user using their email address.
Implementation
Future<GotrueSessionResponse> signInWithEmail(
String email,
String password, {
AuthOptions? options,
}) async {
try {
final body = {'email': email, 'password': password};
final fetchOptions = FetchOptions(headers);
final urlParams = ['grant_type=password'];
if (options?.redirectTo != null) {
final encodedRedirectTo = Uri.encodeComponent(options!.redirectTo!);
urlParams.add('redirect_to=$encodedRedirectTo');
}
final queryString = '?${urlParams.join('&')}';
final response = await _fetch.post(
'$url/token$queryString',
body,
options: fetchOptions,
);
if (response.error != null) {
return GotrueSessionResponse.fromResponse(response: response);
} else {
final session =
Session.fromJson(response.rawData as Map<String, dynamic>);
return GotrueSessionResponse.fromResponse(
response: response,
data: session,
);
}
} catch (e) {
return GotrueSessionResponse(error: GotrueError(e.toString()));
}
}