improve the register workflow

This commit is contained in:
arp 2020-09-18 16:29:53 +02:00
parent 3a17795ad3
commit a19f09bef2
3 changed files with 29 additions and 13 deletions

View file

@ -1,7 +1,7 @@
import {Application, Request, Response} from "express"; import {Application, Request, Response} from "express";
import {OK} from "http-status-codes"; import {OK} from "http-status-codes";
import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable"; import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable";
import Axios, {AxiosError} from "axios"; import Axios from "axios";
export class AdminController { export class AdminController {
App : Application; App : Application;
@ -27,12 +27,10 @@ export class AdminController {
return res.status(e.status || 500).send('An error happened'); 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 worldSlug = response.data.worldSlug;
const roomSlug = response.data.roomSlug; const roomSlug = response.data.roomSlug;
return res.status(OK).send({ return res.status(OK).send({organizationSlug, worldSlug, roomSlug});
loginUrl: '/@/'+teamSlug+'/'+worldSlug+'/'+roomSlug,
});
}); });
} }
} }

View file

@ -14,7 +14,8 @@ import {CoWebsiteManager} from "./WebRtc/CoWebsiteManager";
import {redirectIfToken} from "./register"; import {redirectIfToken} from "./register";
//CoWebsiteManager.loadCoWebsite('https://thecodingmachine.com'); //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. // Load Jitsi if the environment variable is set.
if (JITSI_URL) { if (JITSI_URL) {

View file

@ -1,12 +1,29 @@
import Axios from "axios"; import Axios from "axios";
import {API_URL} from "./Enum/EnvironmentVariable"; import {API_URL} from "./Enum/EnvironmentVariable";
declare let window:Window; declare let history:History;
export function redirectIfToken() { //todo: better naming
const match = window.location.toString().match(/\/register\/(.+)/); export interface ConnexionData {
if (match) { organizationSlug: string,
Axios.get(`${API_URL}/register/`+match[1]).then((res) => { worldSlug: string,
window.location = res.data.loginUrl; roomSlug: string,
}); }
export async function redirectIfToken(): Promise<ConnexionData | null> {
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};
} }