sql数据流,amdin业务逻辑接入

This commit is contained in:
comlibmb
2026-02-05 10:11:09 +08:00
parent 859372ca5b
commit ac670cf5d8
81 changed files with 3547 additions and 1472 deletions

View File

@@ -56,10 +56,12 @@ export async function ensureUserProfile(sessionUser: UTSJSONObject): Promise<Use
}
// 用户不存在,创建新用户资料
// 权威字段映射ak_users.auth_id = auth.uid(),业务主键 id 由数据库自动生成
const newUserData = new UTSJSONObject()
newUserData.set('id', userId)
newUserData.set('auth_id', userId)
newUserData.set('email', email)
newUserData.set('username', email.split('@')[0] ?? 'user') // 默认用户名为邮箱前缀
newUserData.set('role', 'consumer')
const insertRes = await supabase.from('ak_users')
.insert(newUserData)

View File

@@ -64,8 +64,8 @@ export async function getCurrentUser() : Promise<UserProfile | null> {
state.userProfile = { username: '', email: '' }
state.isLoggedIn = false // 未登录
return null
} // 查询 ak_users 表补全 profile
const res = await supa.from('ak_users').select('*', {}).eq('id', userId).execute()
} // 查询 ak_users 表补全 profile权威关联字段auth_id = auth.uid()
const res = await supa.from('ak_users').select('*', {}).eq('auth_id', userId).execute()
console.log(res)
if (res.status >= 200 && res.status < 300 && (res.data != null)) {
let user : UTSJSONObject | null = null;
@@ -182,13 +182,11 @@ export function getUserStore() {
},
getUserRole() : string | null {
// Default role logic - can be enhanced based on your needs
const sessionInfo = supa.getSession()
if (sessionInfo.user == null) return null
// You can add role detection logic here
// For now, return a default role
return 'teacher' // or determine from user profile/database
const profile = state.userProfile
if (profile != null && profile.role != null) {
return profile.role
}
return null
},
getProfile() : UserProfile | null {

View File

@@ -1,6 +1,9 @@
import supa from '@/components/supadb/aksupainstance.uts'
import type { AkReqResponse } from '@/uni_modules/ak-req/index.uts'
// 导出 supa 实例,供 services 层统一使用
export { supa }
// 使用单例 Supabase 客户端
// const supa = createClient(SUPA_URL, SUPA_KEY)