fix(lceonline): user turning null by refreshing token when app is opened (#138)

This commit is contained in:
str1k3r
2026-07-13 07:15:06 -04:00
committed by GitHub
parent 9cf05611a3
commit 1c65b48958

View File

@@ -23,6 +23,9 @@ export class LceOnlineService {
private _listeners: Array<() => void> = [];
constructor() {
this.loadSession();
if (this._session) {
this.refreshToken();
}
}
onSessionChange(listener: () => void): () => void {
@@ -195,6 +198,28 @@ export class LceOnlineService {
return data;
}
async refreshToken(): Promise<boolean> {
if (!this._session) return false;
try {
const res = await this.request<string>("POST", "/refreshtoken", null, AUTH_BASE_URL);
if (typeof res === "string" && res.startsWith("-")) {
const [username, token] = res.slice(1).split(":");
this._session.accessToken = token;
this._session.account = { username, displayName: username };
this.saveSession();
this._notify();
return true;
}
this.logoutLocal();
return false;
} catch (e) {
console.warn("Failed to refresh token", e);
this.logoutLocal()
return false;
}
}
async getSocialLists(): Promise<{
friends: string[];
requests: string[];