feat: 微信登录与认证完善 + 一键 docker compose 启动
登录流程(以 openid 为唯一标识): - auth.service.login 改为 upsert:openid 在库续登,不在库自动建用户签 token - 个人主体无 getPhoneNumber 权限,故不强制手机号注册;register 接口保留备未来用 - wechat.service 新增 getAccessToken(Redis 缓存)、getPluginOpenPid、getUserPhoneNumber - 新增 /api/wechat/plugin-openpid、/api/wechat/phone 接口 schema 与迁移: - User 增加 openpid(可空唯一) 兼容插件场景;openid 保持必填主键 - 新增 add_openpid_optional_openid、openid_required_primary 迁移 部署: - docker-compose.yml 改为 docker compose up -d 一键启动 postgres+redis+app - app 容器内用服务名连 db/redis,启动自动跑 prisma migrate deploy - 端口统一 3090(Dockerfile EXPOSE、compose 映射同步) - 新增 docs/wechat-api-signature-guide.md API 签名手册 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,12 @@ import { PrismaService } from '../prisma/prisma.service';
|
||||
export class UsersService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
/** 按 openid 查询用户,不存在则创建(首次登录) */
|
||||
/** 按 openid 查询用户(登录判定主键) */
|
||||
async findByOpenid(openid: string) {
|
||||
return this.prisma.user.findUnique({ where: { openid } });
|
||||
}
|
||||
|
||||
/** 按 openid 查询,不存在则创建(首次登录自动注册,无需手机号) */
|
||||
async findOrCreateByOpenid(openid: string, unionid?: string) {
|
||||
return this.prisma.user.upsert({
|
||||
where: { openid },
|
||||
@@ -14,6 +19,16 @@ export class UsersService {
|
||||
});
|
||||
}
|
||||
|
||||
/** 首次注册:绑定手机号后创建用户(phone 非空 = 注册完成标记) */
|
||||
async createWithOpenid(
|
||||
openid: string,
|
||||
data: { phone?: string; nickname?: string; avatar?: string; unionid?: string },
|
||||
) {
|
||||
return this.prisma.user.create({
|
||||
data: { openid, ...data },
|
||||
});
|
||||
}
|
||||
|
||||
async findById(id: string) {
|
||||
return this.prisma.user.findUnique({ where: { id } });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user