2023-12-30 23:41:25 +00:00
|
|
|
import { bypassLogin } from "./battle-scene";
|
|
|
|
import * as Utils from "./utils";
|
|
|
|
|
2023-12-31 23:30:37 +00:00
|
|
|
export interface UserInfo {
|
|
|
|
username: string;
|
|
|
|
hasGameSession: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export let loggedInUser: UserInfo = null;
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
export function updateUserInfo(): Promise<boolean> {
|
|
|
|
return new Promise<boolean>(resolve => {
|
|
|
|
if (bypassLogin) {
|
2023-12-31 23:30:37 +00:00
|
|
|
loggedInUser = { username: 'Guest', hasGameSession: !!localStorage.getItem('sessionData') };
|
2023-12-30 23:41:25 +00:00
|
|
|
return resolve(true);
|
|
|
|
}
|
|
|
|
Utils.apiFetch('account/info').then(response => {
|
|
|
|
if (!response.ok) {
|
|
|
|
loggedInUser = null;
|
|
|
|
resolve(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
}).then(jsonResponse => {
|
|
|
|
loggedInUser = jsonResponse;
|
|
|
|
resolve(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|