Fix htag in localstorage

Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com>
This commit is contained in:
Gregoire Parant 2021-11-24 19:24:43 +01:00
parent 445599416c
commit 060c844468
5 changed files with 36 additions and 8 deletions

View file

@ -176,8 +176,9 @@ class ConnectionManager {
//before set token of user we must load room and all information. For example the mandatory authentication could be require on current room
this._currentRoom = await Room.createRoom(new URL(roomPath));
//defined last room url this room path
localUserStore.setLastRoomUrl(this._currentRoom.key);
//Set last room visited! (connected or nor, must to be saved in localstorage and cache API)
//use href to keep # value
localUserStore.setLastRoomUrl(this._currentRoom.href);
//todo: add here some kind of warning if authToken has expired.
if (!this.authToken && !this._currentRoom.authenticationMandatory) {
@ -188,8 +189,15 @@ class ConnectionManager {
analyticsClient.loggedWithSso();
} catch (err) {
console.error(err);
this.loadOpenIDScreen();
return Promise.reject(new Error("You will be redirect on login page"));
//if user must to be connect in current room or pusher error is not openid provier access error
//try to connected with function loadOpenIDScreen
if (
this._currentRoom.authenticationMandatory ||
(err.response?.data && err.response.data !== "User cannot to be connected on openid provier")
) {
this.loadOpenIDScreen();
return Promise.reject(new Error("You will be redirect on login page"));
}
}
}
this.localUser = localUserStore.getLocalUser() as LocalUser; //if authToken exist in localStorage then localUser cannot be null

View file

@ -176,6 +176,10 @@ export class Room {
return newUrl.toString();
}
public get href(): string {
return this.roomUrl.toString();
}
get textures(): CharacterTexture[] | undefined {
return this._textures;
}

View file

@ -45,6 +45,7 @@ export class GameManager {
return EnableCameraSceneName;
} else {
this.activeMenuSceneAndHelpCameraSettings();
//TODO fix to return href with # saved in localstorage
return this.startRoom.key;
}
}

View file

@ -40,7 +40,8 @@ class UrlManager {
public pushRoomIdToUrl(room: Room): void {
if (window.location.pathname === room.id) return;
//Set last room visited! (connected or nor, must to be saved in localstorage and cache API)
localUserStore.setLastRoomUrl(room.key);
//use href to keep # value
localUserStore.setLastRoomUrl(room.href);
const hash = window.location.hash;
const search = room.search.toString();
history.pushState({}, "WorkAdventure", room.id + (search ? "?" + search : "") + hash);