fix(auth): lookupByPhone 支持查询未迁移的 1.0 用户
P2P 转账验证手机号时,lookupByPhone 只查 users 表(V2 注册用户), 导致未登录过 2.0 的 1.0 老用户(CDC 同步在 synced_legacy_users 表) 被报"不存在"。修改为先查 users 表,未找到再查 synced_legacy_users。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
187b82e9ac
commit
f0c7cee94e
|
|
@ -4,6 +4,8 @@ import {
|
|||
Phone,
|
||||
USER_REPOSITORY,
|
||||
UserRepository,
|
||||
SYNCED_LEGACY_USER_REPOSITORY,
|
||||
SyncedLegacyUserRepository,
|
||||
} from '@/domain';
|
||||
|
||||
export interface UserProfileResult {
|
||||
|
|
@ -22,6 +24,8 @@ export class UserService {
|
|||
constructor(
|
||||
@Inject(USER_REPOSITORY)
|
||||
private readonly userRepository: UserRepository,
|
||||
@Inject(SYNCED_LEGACY_USER_REPOSITORY)
|
||||
private readonly syncedLegacyUserRepository: SyncedLegacyUserRepository,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
|
@ -50,20 +54,32 @@ export class UserService {
|
|||
|
||||
/**
|
||||
* 根据手机号查找用户(用于P2P转账验证)
|
||||
* 先查 V2 users 表,未找到再查 synced_legacy_users 表
|
||||
*/
|
||||
async lookupByPhone(phone: string): Promise<{ exists: boolean; accountSequence?: string; nickname?: string }> {
|
||||
const phoneVO = Phone.create(phone);
|
||||
const user = await this.userRepository.findByPhone(phoneVO);
|
||||
|
||||
if (!user || user.status !== 'ACTIVE') {
|
||||
return { exists: false };
|
||||
// 1. 先查 V2 用户表
|
||||
const user = await this.userRepository.findByPhone(phoneVO);
|
||||
if (user && user.status === 'ACTIVE') {
|
||||
return {
|
||||
exists: true,
|
||||
accountSequence: user.accountSequence.value,
|
||||
nickname: user.isKycVerified ? this.maskName(user.realName!) : user.phone.masked,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
exists: true,
|
||||
accountSequence: user.accountSequence.value,
|
||||
nickname: user.isKycVerified ? this.maskName(user.realName!) : user.phone.masked,
|
||||
};
|
||||
// 2. 查 1.0 同步用户表(未迁移的老用户)
|
||||
const legacyUser = await this.syncedLegacyUserRepository.findByPhone(phoneVO);
|
||||
if (legacyUser && legacyUser.status === 'ACTIVE' && !legacyUser.migratedToV2) {
|
||||
return {
|
||||
exists: true,
|
||||
accountSequence: legacyUser.accountSequence.value,
|
||||
nickname: legacyUser.nickname || legacyUser.phone.masked,
|
||||
};
|
||||
}
|
||||
|
||||
return { exists: false };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue