register method Null safety
Creates an account with the given username
, password
and domain
If they're not set, they'll be randomized with a randomStringLength
length.
Implementation
static Future<TMAccount> register({
String? username,
String? password,
Domain? domain,
int randomStringLength = 10,
}) async {
if (username == null || username.isEmpty) {
username = randomString(randomStringLength);
}
if (password == null || password.isEmpty) {
password = randomString(randomStringLength);
}
domain ??= (await Domain.domains).first;
String address = username + '@${domain.domain}';
var data = await Requests.post('/accounts', {
'address': address,
'password': password,
});
String token = await getToken(data['address'], password);
var account = accountFromJson(data, password, token);
auths[data['id']] = Auth(account, token);
return account;
}