fix(auth-service): 密码登录时对手机号做 E.164 归一化
注册时手机号存储为 +8618926762721,但密码登录用原始输入 18926762721 查库,导致找不到用户。在 login() 中先尝试 Phone.create() 归一化,如果不是合法手机号则作为邮箱使用。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
abb358100d
commit
ec0af6c47e
|
|
@ -113,7 +113,14 @@ export class AuthService {
|
|||
/* ── Password Login ── */
|
||||
|
||||
async login(dto: LoginDto): Promise<AuthResult> {
|
||||
const user = await this.userRepo.findByPhoneOrEmail(dto.identifier);
|
||||
// Normalize phone numbers to E.164 before lookup (e.g. 18926762721 → +8618926762721)
|
||||
let identifier = dto.identifier;
|
||||
try {
|
||||
identifier = Phone.create(dto.identifier).value;
|
||||
} catch {
|
||||
// Not a valid phone number — treat as email, use as-is
|
||||
}
|
||||
const user = await this.userRepo.findByPhoneOrEmail(identifier);
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('账号或密码错误');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue