Change accès token with query privateAccessToken in the url
Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com>
This commit is contained in:
parent
31f3b2b48e
commit
876ddc87d2
@ -2,7 +2,7 @@ import Axios from "axios";
|
||||
import { PUSHER_URL } from "../Enum/EnvironmentVariable";
|
||||
import { RoomConnection } from "./RoomConnection";
|
||||
import type { OnConnectInterface, PositionInterface, ViewportInterface } from "./ConnexionModels";
|
||||
import { GameConnexionTypes, urlManager } from "../Url/UrlManager";
|
||||
import { GameConnexionTypes, queryPrivateAccessToken, urlManager } from "../Url/UrlManager";
|
||||
import { localUserStore } from "./LocalUserStore";
|
||||
import { CharacterTexture, LocalUser } from "./LocalUser";
|
||||
import { Room } from "./Room";
|
||||
@ -124,8 +124,42 @@ class ConnectionManager {
|
||||
return Promise.reject(new Error("You will be redirect on login page"));
|
||||
}
|
||||
urlManager.pushRoomIdToUrl(this._currentRoom);
|
||||
} else if (connexionType === GameConnexionTypes.register) {
|
||||
} else if (connexionType === GameConnexionTypes.privateAccessToken) {
|
||||
const organizationMemberToken = urlManager.getPrivateAccessToken;
|
||||
|
||||
//clear queryPrivateAccessToken query in window location
|
||||
urlParams.delete(queryPrivateAccessToken);
|
||||
|
||||
const data = await Axios.post(`${PUSHER_URL}/register`, { organizationMemberToken }).then(
|
||||
(res) => res.data
|
||||
);
|
||||
if (!isRegisterData(data)) {
|
||||
console.error("Invalid data received from /register route. Data: ", data);
|
||||
throw new Error("Invalid data received from /register route.");
|
||||
}
|
||||
this.localUser = new LocalUser(data.userUuid, data.textures, data.email);
|
||||
this.authToken = data.authToken;
|
||||
localUserStore.saveUser(this.localUser);
|
||||
localUserStore.setAuthToken(this.authToken);
|
||||
analyticsClient.loggedWithToken();
|
||||
|
||||
const roomUrl = data.roomUrl;
|
||||
|
||||
const query = urlParams.toString();
|
||||
this._currentRoom = await Room.createRoom(
|
||||
new URL(
|
||||
window.location.protocol +
|
||||
"//" +
|
||||
window.location.host +
|
||||
roomUrl +
|
||||
(query ? "?" + query : "") + //use urlParams because the token param must be deleted
|
||||
window.location.hash
|
||||
)
|
||||
);
|
||||
urlManager.pushRoomIdToUrl(this._currentRoom);
|
||||
}
|
||||
//@deprecated
|
||||
else if (connexionType === GameConnexionTypes.register) {
|
||||
const organizationMemberToken = urlManager.getOrganizationToken();
|
||||
const data = await Axios.post(`${PUSHER_URL}/register`, { organizationMemberToken }).then(
|
||||
(res) => res.data
|
||||
|
@ -3,13 +3,16 @@ import { localUserStore } from "../Connexion/LocalUserStore";
|
||||
|
||||
export enum GameConnexionTypes {
|
||||
room = 1,
|
||||
register,
|
||||
register /*@deprecated*/,
|
||||
empty,
|
||||
unknown,
|
||||
jwt,
|
||||
login,
|
||||
privateAccessToken,
|
||||
}
|
||||
|
||||
export const queryPrivateAccessToken = "privateAccessToken";
|
||||
|
||||
//this class is responsible with analysing and editing the game's url
|
||||
class UrlManager {
|
||||
public getGameConnexionType(): GameConnexionTypes {
|
||||
@ -19,8 +22,13 @@ class UrlManager {
|
||||
} else if (url === "/jwt") {
|
||||
return GameConnexionTypes.jwt;
|
||||
} else if (url.includes("_/") || url.includes("*/") || url.includes("@/")) {
|
||||
if (window.location.search.includes(queryPrivateAccessToken)) {
|
||||
return GameConnexionTypes.privateAccessToken;
|
||||
}
|
||||
return GameConnexionTypes.room;
|
||||
} else if (url.includes("register/")) {
|
||||
}
|
||||
//@deprecated register url will be replace by "?privateAccessToken=<private access token>"
|
||||
else if (url.includes("register/")) {
|
||||
return GameConnexionTypes.register;
|
||||
} else if (url === "/") {
|
||||
return GameConnexionTypes.empty;
|
||||
@ -29,6 +37,17 @@ class UrlManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
get getPrivateAccessToken(): string | null {
|
||||
const urlParams = new URLSearchParams(window.location.search.toString());
|
||||
return urlParams.get(queryPrivateAccessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public getOrganizationToken(): string | null {
|
||||
const match = /\/register\/(.+)/.exec(window.location.pathname.toString());
|
||||
return match ? match[1] : null;
|
||||
|
Loading…
Reference in New Issue
Block a user