mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-09-23 08:32:51 +00:00
fix(lceonline): being logged out every app open (#194)
This commit is contained in:
@@ -36,9 +36,6 @@ export class LceOnlineService {
|
|||||||
private _listeners: Array<() => void> = [];
|
private _listeners: Array<() => void> = [];
|
||||||
constructor() {
|
constructor() {
|
||||||
this.loadSession();
|
this.loadSession();
|
||||||
if (this._session) {
|
|
||||||
this.refreshToken();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSessionChange(listener: () => void): () => void {
|
onSessionChange(listener: () => void): () => void {
|
||||||
@@ -212,28 +209,6 @@ export class LceOnlineService {
|
|||||||
return data;
|
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 data = JSON.parse(res);
|
|
||||||
this._session.accessToken = data.token;
|
|
||||||
this._session.account = { username: data.username, displayName: data.displayName };
|
|
||||||
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() {
|
async getSocialLists() {
|
||||||
const res = await this.request<SocialList>("GET", "/getSocialLists", null);
|
const res = await this.request<SocialList>("GET", "/getSocialLists", null);
|
||||||
if (typeof res === "string") throw new Error(res);
|
if (typeof res === "string") throw new Error(res);
|
||||||
|
|||||||
Reference in New Issue
Block a user