From c1dc438138f5ec474f9407944c00428d45955178 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 11:14:27 +0100 Subject: [PATCH 1/2] HotFix encrypted and decrypted error Signed-off-by: Gregoire Parant --- front/src/Connexion/Room.ts | 48 ++++++++++++++++---------- pusher/src/Controller/MapController.ts | 15 +++++--- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index 535d2f8d..0f4bb20c 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -89,27 +89,37 @@ export class Room { } private async getMapDetail(): Promise { - const result = await Axios.get(`${PUSHER_URL}/map`, { - params: { - playUri: this.roomUrl.toString(), - authToken: localUserStore.getAuthToken(), - }, - }); + try { + const result = await Axios.get(`${PUSHER_URL}/map`, { + params: { + playUri: this.roomUrl.toString(), + authToken: localUserStore.getAuthToken(), + }, + }); - const data = result.data; - if (data.redirectUrl) { - return { - redirectUrl: data.redirectUrl as string, - }; + const data = result.data; + if (data.redirectUrl) { + return { + redirectUrl: data.redirectUrl as string, + }; + } + console.log("Map ", this.id, " resolves to URL ", data.mapUrl); + this._mapUrl = data.mapUrl; + this._textures = data.textures; + this._group = data.group; + this._authenticationMandatory = data.authenticationMandatory || (DISABLE_ANONYMOUS as boolean); + this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER; + this._contactPage = data.contactPage || CONTACT_URL; + return new MapDetail(data.mapUrl, data.textures); + } catch (e) { + console.log("Error => getMapDetail", e, e.response); + //TODO fix me and manage Error class + if (e.response?.data === "Token decrypted error") { + localUserStore.setAuthToken(null); + window.location.assign("/login"); + } + throw e; } - console.log("Map ", this.id, " resolves to URL ", data.mapUrl); - this._mapUrl = data.mapUrl; - this._textures = data.textures; - this._group = data.group; - this._authenticationMandatory = data.authenticationMandatory || (DISABLE_ANONYMOUS as boolean); - this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER; - this._contactPage = data.contactPage || CONTACT_URL; - return new MapDetail(data.mapUrl, data.textures); } /** diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index 18748d9e..d7d506e2 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -80,10 +80,17 @@ export class MapController extends BaseController { authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string); userId = authTokenData.identifier; } catch (e) { - // Decode token, in this case we don't need to create new token. - authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string, true); - userId = authTokenData.identifier; - console.info("JWT expire, but decoded", userId); + try { + // Decode token, in this case we don't need to create new token. + authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string, true); + userId = authTokenData.identifier; + console.info("JWT expire, but decoded", userId); + } catch (e) { + // The token was not good, redirect user on login page + res.writeStatus("500"); + res.end("Token decrypted error"); + return; + } } } const mapDetails = await adminApi.fetchMapDetails(query.playUri as string, userId); From ec1cc92c8b12b36d8d08483e58b758593ba8c015 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 11:23:18 +0100 Subject: [PATCH 2/2] replace console log by error Signed-off-by: Gregoire Parant --- front/src/Connexion/Room.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index 0f4bb20c..dd80b704 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -112,7 +112,7 @@ export class Room { this._contactPage = data.contactPage || CONTACT_URL; return new MapDetail(data.mapUrl, data.textures); } catch (e) { - console.log("Error => getMapDetail", e, e.response); + console.error("Error => getMapDetail", e, e.response); //TODO fix me and manage Error class if (e.response?.data === "Token decrypted error") { localUserStore.setAuthToken(null);