signInWithSmsPasswordless method
Authenticates a user using a phoneNumber
.
The returned AuthResponse
will only have its AuthResponse.mfa
field
set, which can then be used to complete the sign in via
completeSmsPasswordlessSignIn alongside the user's one-time-password.
Throws an NhostException
if sign in fails.
Implementation
@override
Future<void> signInWithSmsPasswordless({
required String phoneNumber,
String? locale,
String? defaultRole,
Map<String, Object?>? metadata,
List<String>? roles,
String? displayName,
String? redirectTo,
}) async {
log.finer('Attempting sign in (passwordless SMS)');
final includeRoleOptions =
defaultRole != null || (roles != null && roles.isNotEmpty);
final options = {
if (metadata != null) 'metadata': metadata,
if (locale != null) 'locale': locale,
if (includeRoleOptions) 'defaultRole': defaultRole,
if (includeRoleOptions) 'allowedRoles': roles,
if (displayName != null) 'displayName': displayName,
if (redirectTo != null) 'redirectTo': redirectTo,
};
await _apiClient.post(
'/signin/passwordless/sms',
jsonBody: {
'phoneNumber': phoneNumber,
if (options.isNotEmpty) 'options': options,
},
);
}