registerByPhoneCode static method

Future<AuthResult> registerByPhoneCode(
  1. String phone,
  2. String code,
  3. String password, {
  4. String? phoneCountryCode,
  5. AuthRequest? authData,
})

register a new user by phone number and an SMS verification code.

Implementation

static Future<AuthResult> registerByPhoneCode(
    String phone, String code, String password,
    {String? phoneCountryCode, AuthRequest? authData}) async {
  Map map = {};
  map.putIfAbsent('phone', () => phone);
  map.putIfAbsent('code', () => code);
  map.putIfAbsent('password', () => Util.encrypt(password));
  map.putIfAbsent('forceLogin', () => true);
  if (phoneCountryCode != null) {
    map.putIfAbsent('phoneCountryCode', () => phoneCountryCode);
  }

  final Result result =
      await post('/api/v2/register/phone-code', jsonEncode(map));
  AuthResult authResult = AuthResult(result);
  authResult.user = await createUser(result);
  if (authData == null) {
    return authResult;
  } else {
    if (authResult.code == 200) {
      authData.token = authResult.user?.token ?? "";
      return OIDCClient.authByToken(authData.token, authData);
    } else {
      return authResult;
    }
  }
}