fix: 修复首次登录会话恢复

This commit is contained in:
que01 committed 2026-10-19 10:58:26 +08:00
1 parent 4ef4be2071
commit 8e29932bc6
6 files changed
+746 -714

No files matched your search

+19 -10
View File
@@ -55,21 +55,30 @@ export class AdminAuthService {
}
async currentSession(request: FastifyRequest): Promise<AdminCurrentSession> {
const access = await this.access.requireBrand(request);
const user = await this.prisma.adminUser.findUniqueOrThrow({
where: { id: access.subject },
select: {
displayName: true,
mustChangePassword: true,
platformTemplateRole: true,
},
});
// current 必须能返回首次登录态;不能先执行 requireBrand 把 mustChangePassword 用户挡在登录页。
const access = await this.access.requireToken(request);
const [user, membership] = await Promise.all([
this.prisma.adminUser.findUniqueOrThrow({
where: { id: access.subject },
select: {
displayName: true,
mustChangePassword: true,
platformTemplateRole: true,
},
}),
this.prisma.brandMembership.findUnique({
where: {
adminUserId_brandId: { adminUserId: access.subject, brandId: access.brandId },
},
}),
]);
if (!membership?.isEnabled) throw new ForbiddenException("管理员没有当前品牌权限");
return {
authenticated: true,
displayName: user.displayName,
mustChangePassword: user.mustChangePassword,
platformTemplateRole: user.platformTemplateRole,
role: access.role,
role: membership.role,
};
}