signUpWithPhone method
Signs up a new user using their phone number and a password.
phone
is the user's phone number WITH international prefix
password
is the password of the user
userMetadata
sets User.userMetadata without an extra call to updateUser
Implementation
Future<GotrueSessionResponse> signUpWithPhone(
String phone,
String password, {
Map<String, dynamic>? userMetadata,
}) async {
try {
final fetchOptions = FetchOptions(headers);
final body = {
'phone': phone,
'password': password,
'data': userMetadata,
};
final response =
await _fetch.post('$url/signup', body, options: fetchOptions);
final data = response.rawData as Map<String, dynamic>?;
if (response.error != null) {
return GotrueSessionResponse.fromResponse(
response: response,
);
} else if (data != null && data['access_token'] == null) {
// email validation required
User? user;
if (data['id'] != null) {
user = User.fromJson(data);
}
return GotrueSessionResponse.fromResponse(
response: response,
user: user,
);
} 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()));
}
}