improve the register workflow
This commit is contained in:
parent
3a17795ad3
commit
a19f09bef2
3 changed files with 29 additions and 13 deletions
|
@ -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<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};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue