子账号登录微信授权

This commit is contained in:
2026-07-10 11:03:11 +08:00
parent f4f4f1b4aa
commit 9c5cb69730
11 changed files with 535 additions and 251 deletions
@@ -172,6 +172,11 @@ export class PartnerAuthController {
}
return this.authService.loginPartnerWechat(dto.code, ClientApp.PARTNER_H5, dto.platform ?? 'h5');
}
@Post('token/refresh')
refresh(@Body() dto: RefreshTokenDto) {
return this.authService.refreshAccessToken(dto.refreshToken, ClientApp.PARTNER_H5);
}
}
@Controller('user')
@@ -385,6 +385,9 @@ export class AuthService {
if (payload.actorType === 'STORE' && clientApp === ClientApp.SHOP_H5) {
return this.buildStoreSessionResponse(BigInt(payload.actorId), clientApp);
}
if (payload.actorType === 'PARTNER' && clientApp === ClientApp.PARTNER_H5) {
return this.buildPartnerSessionResponse(BigInt(payload.actorId), clientApp);
}
throw new UnauthorizedException('Invalid refresh token');
} catch (err) {
if (err instanceof UnauthorizedException) throw err;
@@ -409,6 +412,25 @@ export class AuthService {
});
}
private async buildPartnerSessionResponse(accountId: bigint, clientApp: ClientApp) {
const account = await this.prisma.partnerAccount.findUnique({
where: { id: accountId },
include: { partner: true },
});
if (!account || account.status !== 'ACTIVE') {
throw new UnauthorizedException('Invalid refresh token');
}
return this.issueToken('PARTNER', account.id, clientApp, false, undefined, undefined, {
id: account.id.toString(),
partnerId: account.partnerId.toString(),
name: account.name,
phone: account.phone,
isPrimary: account.isPrimary === 1,
staffRole: account.staffRole ?? undefined,
companyName: account.partner.companyName,
});
}
async loginUser(phone: string, code: string, clientApp: ClientApp, guestId?: bigint) {
const normalizedPhone = this.assertMobilePhone(phone);
const existingUser = await this.prisma.user.findUnique({
@@ -1393,7 +1415,7 @@ export class AuthService {
phoneVerified,
};
const accessToken = this.jwtService.sign(payload);
const refreshExpiresIn = actorType === 'STORE' ? '7d' : '30d';
const refreshExpiresIn = actorType === 'STORE' || actorType === 'PARTNER' ? '7d' : '30d';
const refreshToken = this.jwtService.sign(payload, { expiresIn: refreshExpiresIn });
return {
accessToken,