diff --git a/back/src/Controller/AdminController.ts b/back/src/Controller/AdminController.ts index 7c20498f..c4905a8a 100644 --- a/back/src/Controller/AdminController.ts +++ b/back/src/Controller/AdminController.ts @@ -1,7 +1,7 @@ import {Application, Request, Response} from "express"; import {OK} from "http-status-codes"; import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable"; -import Axios, {AxiosError} from "axios"; +import Axios from "axios"; export class AdminController { App : Application; @@ -27,12 +27,10 @@ export class AdminController { return res.status(e.status || 500).send('An error happened'); } - const teamSlug = response.data.teamSlug; + const organizationSlug = response.data.organizationSlug; const worldSlug = response.data.worldSlug; const roomSlug = response.data.roomSlug; - return res.status(OK).send({ - loginUrl: '/@/'+teamSlug+'/'+worldSlug+'/'+roomSlug, - }); + return res.status(OK).send({organizationSlug, worldSlug, roomSlug}); }); } } diff --git a/front/src/index.ts b/front/src/index.ts index 8be675fb..1f6b1d4a 100644 --- a/front/src/index.ts +++ b/front/src/index.ts @@ -14,7 +14,8 @@ import {CoWebsiteManager} from "./WebRtc/CoWebsiteManager"; import {redirectIfToken} from "./register"; //CoWebsiteManager.loadCoWebsite('https://thecodingmachine.com'); -redirectIfToken(); +let connectionData //todo: do something with this data +redirectIfToken().then(res => connectionData = res); // Load Jitsi if the environment variable is set. if (JITSI_URL) { diff --git a/front/src/register.ts b/front/src/register.ts index 0cc9dd13..98fe0d1e 100644 --- a/front/src/register.ts +++ b/front/src/register.ts @@ -1,12 +1,29 @@ import Axios from "axios"; import {API_URL} from "./Enum/EnvironmentVariable"; -declare let window:Window; +declare let history:History; -export function redirectIfToken() { - const match = window.location.toString().match(/\/register\/(.+)/); - if (match) { - Axios.get(`${API_URL}/register/`+match[1]).then((res) => { - window.location = res.data.loginUrl; - }); +//todo: better naming +export interface ConnexionData { + organizationSlug: string, + worldSlug: string, + roomSlug: string, +} + +export async function redirectIfToken(): Promise { + const match = /\/register\/(.+)/.exec(window.location.toString()); + if (!match) { + return null } + let res = null; + try { + res = await Axios.get(`${API_URL}/register/`+match[1]) + } catch (e) { + return null; + } + const organizationSlug = res.data.organizationSlug; + const worldSlug = res.data.worldSlug; + const roomSlug = res.data.roomSlug; + const connexionUrl = '/@/'+organizationSlug+'/'+worldSlug+'/'+roomSlug; + history.pushState({}, '', connexionUrl); + return {organizationSlug, worldSlug, roomSlug}; } \ No newline at end of file