feat: 支持按品牌配置微信登录凭据
CI / Browser smoke (pull_request) Successful in 58s
CI / Static checks (pull_request) Successful in 1m32s
CI / API integration (pull_request) Successful in 1m27s
CI / Production build (pull_request) Successful in 2m7s

This commit is contained in:
que01 committed 2026-10-23 22:07:39 +08:00
1 parent e75c524343
commit d0a0eeea8c
23 files changed
+460 -62

No files matched your search

@@ -1,7 +1,11 @@
import { BadRequestException, Injectable } from "@nestjs/common";
import { PrismaService } from "../../prisma.service.js";
import { signIdentity } from "../../auth.js";
import type { WechatSession } from "../../wechat-auth.js";
import {
WechatAuthService,
resolveWechatLoginCredentials,
type WechatSession,
} from "../../wechat-auth.js";
import { PublicBrandContextService } from "../public/public-brand-context.service.js";
@Injectable()
@@ -9,15 +13,18 @@ export class CustomerSessionService {
constructor(
private readonly prisma: PrismaService,
private readonly brandContext: PublicBrandContextService,
private readonly wechatAuth: WechatAuthService,
) {}
async loginWithWechat(session: WechatSession, brandSlug?: string): Promise<{ token: string }> {
async loginWithWechat(code: string, brandSlug?: string): Promise<{ token: string }> {
const brandId = await this.brandContext.resolveId(brandSlug);
const brand = await this.prisma.brandProfile.findUnique({
where: { id: brandId },
select: { id: true },
select: { id: true, miniAppSettings: true },
});
if (!brand) throw new BadRequestException("品牌尚未初始化");
const credentials = resolveWechatLoginCredentials(brand.miniAppSettings);
const session: WechatSession = await this.wechatAuth.exchangeCode(code, credentials);
const customer = await this.prisma.customerUser.upsert({
where: { brandId_openid: { brandId: brand.id, openid: session.openid } },
update: { lastLoginAt: new Date() },