signUp method
Implementation
@override
Future<AuthUser?> signUp(String email, String password, {String? name}) async {
final String address = _address(email);
_checkPassword(password);
// Hashed before the address is looked up, so a taken address does not
// answer sooner than a free one.
final String passwordHash = _hasher.hash(password);
await _ensure();
if (await _byEmail(address) != null) throw _exists;
final AuthUser user =
AuthUser(id: 'acct_${_randomString(24)}', email: address, name: name);
try {
await adapter.execute(
'INSERT INTO $table (id, email, name, password_hash, created_at) '
'VALUES (?, ?, ?, ?, ?)',
<Object?>[
user.id,
address,
name,
passwordHash,
_clock().toUtc().millisecondsSinceEpoch,
],
);
} on Object {
// Another sign-up for this address got there between the lookup and
// the insert, and the unique key refused this one.
if (await _byEmail(address) != null) throw _exists;
rethrow;
}
_changes.add(user);
return user;
}