web/admin: fix error when me() returns 403

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-22 19:52:01 +02:00
parent 9d3b6f7a4d
commit 71e4936dc3
1 changed files with 7 additions and 1 deletions

View File

@ -5,10 +5,16 @@ let _globalMePromise: Promise<SessionUser>;
export function me(): Promise<SessionUser> {
if (!_globalMePromise) {
_globalMePromise = new CoreApi(DEFAULT_CONFIG).coreUsersMe().catch((ex) => {
const defaultUser: SessionUser = {
user: {
username: "",
name: ""
}
};
if (ex.status === 401 || ex.status === 403) {
window.location.assign("/");
}
return ex;
return defaultUser;
});
}
return _globalMePromise;