|
|
@@ -42,7 +42,7 @@ export function generateToken(userId: string, phone?: string): string {
|
|
|
}
|
|
|
|
|
|
// 手机号登录/注册
|
|
|
-export async function loginWithPhone(phone: string, code?: string, inviteCode?: string): Promise<{
|
|
|
+export async function loginWithPhone(phone: string, code?: string, inviteCode?: string, openid?: string): Promise<{
|
|
|
token: string;
|
|
|
user: {
|
|
|
id: string;
|
|
|
@@ -72,6 +72,7 @@ export async function loginWithPhone(phone: string, code?: string, inviteCode?:
|
|
|
user = await prisma.user.create({
|
|
|
data: {
|
|
|
phone,
|
|
|
+ openid: openid || null, // 首次注册时绑定 openid
|
|
|
nickname: `用户${phone.slice(-4)}`,
|
|
|
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${phone}`,
|
|
|
memberLevel: 0,
|
|
|
@@ -90,6 +91,12 @@ export async function loginWithPhone(phone: string, code?: string, inviteCode?:
|
|
|
await handleInvite(shareRecord.userId, user.id, inviteCode);
|
|
|
}
|
|
|
}
|
|
|
+ } else if (openid && !user.openid) {
|
|
|
+ // 老用户登录时,如果之前没有 openid,则绑定
|
|
|
+ user = await prisma.user.update({
|
|
|
+ where: { id: user.id },
|
|
|
+ data: { openid },
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
const token = generateToken(user.id.toString(), phone);
|