feat(auth): transition from email to phone-based OTP authentication

- Replace Email+Password login with Phone+OTP flow
- Remove RegisterCubit and registration screens (email verification)
- Remove ResetPasswordCubit and reset password screens
- Add phone normalization and international dial code support
- Update LoginCubit with sendCode/resend cooldown logic
- Add new widgets: phone prefix selector, confirm sheet
- Update all auth API endpoints: /otp/send, /phone-session
- Update form inputs: Email -> Phone with E.164 validation
- Update tests for new auth flow
This commit is contained in:
qzl
2026-03-19 18:42:05 +08:00
parent 636b37ee5a
commit 0661016827
29 changed files with 615 additions and 2030 deletions
@@ -1,37 +1,28 @@
class SignupStartRequest {
final String username;
final String email;
final String password;
final String? inviteCode;
class OtpSendRequest {
final String phone;
const SignupStartRequest({
required this.username,
required this.email,
required this.password,
this.inviteCode,
});
const OtpSendRequest({required this.phone});
Map<String, dynamic> toJson() => {'phone': _normalizePhone(phone)};
}
class PhoneSessionRequest {
final String phone;
final String token;
const PhoneSessionRequest({required this.phone, required this.token});
Map<String, dynamic> toJson() => {
'username': username,
'email': email,
'password': password,
if (inviteCode != null) 'invite_code': inviteCode,
'phone': _normalizePhone(phone),
'token': token,
};
}
class SignupVerifyRequest {
final String email;
final String token;
const SignupVerifyRequest({required this.email, required this.token});
Map<String, dynamic> toJson() => {'email': email, 'token': token};
}
class SignupResendRequest {
final String email;
const SignupResendRequest({required this.email});
Map<String, dynamic> toJson() => {'email': email};
String _normalizePhone(String input) {
var normalized = input.trim();
normalized = normalized.replaceAll(RegExp(r'[\s\-\(\)]'), '');
if (normalized.startsWith('00') && normalized.length > 2) {
return '+${normalized.substring(2)}';
}
return normalized;
}