数据分析ui补充完善,接入数据库
This commit is contained in:
@@ -19,16 +19,25 @@ export async function ensureUserProfile(sessionUser: UTSJSONObject): Promise<Use
|
||||
return null
|
||||
}
|
||||
|
||||
// 检查用户是否已存在
|
||||
// 检查用户是否已存在(ak_users 通过 auth_id 关联 auth.users.id)
|
||||
const checkRes = await supabase.from('ak_users')
|
||||
.select('*', {})
|
||||
.eq('id', userId)
|
||||
.eq('auth_id', userId)
|
||||
.single()
|
||||
.execute()
|
||||
|
||||
console.log('ensureUserProfile check ak_users:', {
|
||||
status: checkRes.status,
|
||||
hasData: checkRes.data != null,
|
||||
hasError: (checkRes as any).error != null,
|
||||
error: (checkRes as any).error
|
||||
})
|
||||
|
||||
if (checkRes.status >= 200 && checkRes.status < 300 && checkRes.data != null) {
|
||||
// 用户已存在,返回现有资料
|
||||
const existingUser = checkRes.data as UTSJSONObject
|
||||
// 用户已存在,返回现有资料(H5 下 checkRes.data 可能是 plain object,不一定是 UTSJSONObject)
|
||||
const existingUser = (typeof (checkRes.data as any).getString === 'function')
|
||||
? (checkRes.data as UTSJSONObject)
|
||||
: new UTSJSONObject(checkRes.data as any)
|
||||
return {
|
||||
id: existingUser.getString('id') ?? '',
|
||||
username: existingUser.getString('username') ?? '',
|
||||
@@ -58,8 +67,17 @@ export async function ensureUserProfile(sessionUser: UTSJSONObject): Promise<Use
|
||||
.single()
|
||||
.execute()
|
||||
|
||||
console.log('ensureUserProfile insert ak_users:', {
|
||||
status: insertRes.status,
|
||||
hasData: insertRes.data != null,
|
||||
hasError: (insertRes as any).error != null,
|
||||
error: (insertRes as any).error
|
||||
})
|
||||
|
||||
if (insertRes.status >= 200 && insertRes.status < 300 && insertRes.data != null) {
|
||||
const newUser = insertRes.data as UTSJSONObject
|
||||
const newUser = (typeof (insertRes.data as any).getString === 'function')
|
||||
? (insertRes.data as UTSJSONObject)
|
||||
: new UTSJSONObject(insertRes.data as any)
|
||||
return {
|
||||
id: newUser.getString('id') ?? '',
|
||||
username: newUser.getString('username') ?? '',
|
||||
|
||||
Reference in New Issue
Block a user