createPhoneAccount static method
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 errortype
:error
if there was an errormessage
:String
containing the error messagecode
: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.createPhoneSession(
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.createPhoneSession(
userId: ID.unique(),
phone: phone,
);
return token.toMap();
} on AppwriteException catch (e) {
return {
'error': true,
'type': e.type,
'message': e.message,
'code': e.code,
};
}
}