signInWithSmsPasswordless method

  1. @override
Future<void> signInWithSmsPasswordless({
  1. required String phoneNumber,
  2. String? locale,
  3. String? defaultRole,
  4. Map<String, Object?>? metadata,
  5. List<String>? roles,
  6. String? displayName,
  7. String? redirectTo,
})

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,
    },
  );
}