mall数据库文件
This commit is contained in:
@@ -624,6 +624,56 @@ export class AkSupa {
|
||||
this.baseUrl = baseUrl;
|
||||
this.apikey = apikey;
|
||||
this.storage = new AkSupaStorageApi(this);
|
||||
// [CHANGE][2026-01-30] hydrate user/session from persisted token (see docs: components/supadb/docs/CHANGELOG.md)
|
||||
try {
|
||||
this.hydrateSessionFromStorage();
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// [CHANGE][2026-01-30] hydrate user from /auth/v1/user when token exists in storage
|
||||
async hydrateSessionFromStorage() : Promise<boolean> {
|
||||
try {
|
||||
const token = AkReq.getToken();
|
||||
if (token == null || token == '') return false;
|
||||
const res = await AkReq.request({
|
||||
url: this.baseUrl + '/auth/v1/user',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
apikey: this.apikey,
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
} as UTSJSONObject
|
||||
}, false);
|
||||
const status = res.status ?? 0;
|
||||
if (!(status >= 200 && status < 400)) {
|
||||
return false;
|
||||
}
|
||||
let user: UTSJSONObject | null = null;
|
||||
try {
|
||||
user = new UTSJSONObject(res.data);
|
||||
} catch (e) {
|
||||
user = null;
|
||||
}
|
||||
if (user == null) return false;
|
||||
this.user = user;
|
||||
// 仅补齐最小 session 结构,供 getSession / UI 判断登录态使用
|
||||
if (this.session == null) {
|
||||
this.session = {
|
||||
access_token: token,
|
||||
refresh_token: AkReq.getRefreshToken() ?? '',
|
||||
expires_at: AkReq.getExpiresAt() ?? 0,
|
||||
user: user,
|
||||
token_type: 'bearer',
|
||||
expires_in: 0,
|
||||
raw: user
|
||||
} as any;
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async resetPassword(email : string) : Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user