Integrate email notifications into signup and login (#38)
This commit is contained in:
1 parent
326d58f705
commit
ad5a061164
55 files changed
+1859
-3464
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import '../dto/backend.dart';
|
||||
import '../models/auth.dart';
|
||||
import '../models/session.dart';
|
||||
import '../models/two_factor.dart';
|
||||
|
||||
abstract final class BackendMapper {
|
||||
static AuthResult signup(BackendDTO dto) {
|
||||
if (dto.userId.isEmpty) throw const FormatException('Missing user');
|
||||
return AuthResult(userId: dto.userId, isSimulated: false);
|
||||
}
|
||||
|
||||
static FactorChallenge challenge(BackendDTO dto, String id) =>
|
||||
FactorChallenge(
|
||||
id: id,
|
||||
purpose: FactorPurpose.login,
|
||||
operation: id,
|
||||
target: dto.target,
|
||||
expiresAt: dto.expiresAt,
|
||||
resendAt: dto.resendAt,
|
||||
);
|
||||
static AuthSession session(BackendDTO dto) {
|
||||
if (dto.accessToken.isEmpty || dto.userId.isEmpty) {
|
||||
throw const FormatException('Missing session');
|
||||
}
|
||||
return AuthSession(dto.userId, dto.accessToken, dto.refreshToken);
|
||||
}
|
||||
|
||||
static AuthException authFailure(int status, BackendDTO dto) =>
|
||||
AuthException(switch (dto.error) {
|
||||
'email_in_use' => AuthError.emailInUse,
|
||||
'account_not_verified' => AuthError.accountNotVerified,
|
||||
_ when status == 401 => AuthError.invalidCredentials,
|
||||
_ when status == 429 => AuthError.factorCooldown,
|
||||
_ => AuthError.unavailable,
|
||||
});
|
||||
static FactorException factorFailure(int status, BackendDTO dto) =>
|
||||
FactorException(switch (dto.error) {
|
||||
'expired' => FactorError.expired,
|
||||
'locked' => FactorError.locked,
|
||||
'invalid' => FactorError.invalid,
|
||||
_ when status == 429 => FactorError.cooldown,
|
||||
_ when status == 401 => FactorError.expired,
|
||||
_ => FactorError.unavailable,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user