createPhoneAccount static method

Future<Map<String, dynamic>> createPhoneAccount({
  1. required String phone,
  2. bool connectMode = false,
})

Returns a map with the following keys: if there was no error:

  • token: Token from Appwrite if there was an error:
  • error: true if there was an error
  • type: error if there was an error
  • message: String containing the error message
  • code: int containing the error code

Implementation

static Future<Map<String, dynamic>> createPhoneAccount({
  /// Phone number of the user to signup
  required String phone,

  /// Connect the phone number to an existing account
  bool connectMode = false,
}) async {
  try {
    // if (connectMode) {
    //   if (isLoggedIn) {
    //     final models.Token token = await _account.createPhoneToken(
    //       userId: _session!.userId,
    //       phone: phone,
    //     );
    //     return token.toMap();
    //   } else {
    //     throw AppwriteException(
    //       'You need to be logged in to connect a phone number',
    //       401,
    //       'No session found',
    //       null,
    //     );
    //   }
    // }

    final models.Token token = await _account.createPhoneToken(
      userId: ID.unique(),
      phone: phone,
    );

    return token.toMap();
  } on AppwriteException catch (e) {
    return {
      'error': true,
      'type': e.type,
      'message': e.message,
      'code': e.code,
    };
  }
}