Applying Prettier on pusher and back
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import { v4 } from 'uuid';
|
||||
import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js";
|
||||
import {BaseController} from "./BaseController";
|
||||
import {adminApi} from "../Services/AdminApi";
|
||||
import {jwtTokenManager} from "../Services/JWTTokenManager";
|
||||
import {parse} from "query-string";
|
||||
import { v4 } from "uuid";
|
||||
import { HttpRequest, HttpResponse, TemplatedApp } from "uWebSockets.js";
|
||||
import { BaseController } from "./BaseController";
|
||||
import { adminApi } from "../Services/AdminApi";
|
||||
import { jwtTokenManager } from "../Services/JWTTokenManager";
|
||||
import { parse } from "query-string";
|
||||
|
||||
export interface TokenInterface {
|
||||
userUuid: string
|
||||
userUuid: string;
|
||||
}
|
||||
|
||||
export class AuthenticateController extends BaseController {
|
||||
|
||||
constructor(private App : TemplatedApp) {
|
||||
constructor(private App: TemplatedApp) {
|
||||
super();
|
||||
this.register();
|
||||
this.verify();
|
||||
@@ -19,7 +18,7 @@ export class AuthenticateController extends BaseController {
|
||||
}
|
||||
|
||||
//Try to login with an admin token
|
||||
private register(){
|
||||
private register() {
|
||||
this.App.options("/register", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
|
||||
@@ -29,15 +28,15 @@ export class AuthenticateController extends BaseController {
|
||||
this.App.post("/register", (res: HttpResponse, req: HttpRequest) => {
|
||||
(async () => {
|
||||
res.onAborted(() => {
|
||||
console.warn('Login request was aborted');
|
||||
})
|
||||
console.warn("Login request was aborted");
|
||||
});
|
||||
const param = await res.json();
|
||||
|
||||
//todo: what to do if the organizationMemberToken is already used?
|
||||
const organizationMemberToken:string|null = param.organizationMemberToken;
|
||||
const organizationMemberToken: string | null = param.organizationMemberToken;
|
||||
|
||||
try {
|
||||
if (typeof organizationMemberToken != 'string') throw new Error('No organization token');
|
||||
if (typeof organizationMemberToken != "string") throw new Error("No organization token");
|
||||
const data = await adminApi.fetchMemberDataByToken(organizationMemberToken);
|
||||
const userUuid = data.userUuid;
|
||||
const organizationSlug = data.organizationSlug;
|
||||
@@ -49,28 +48,26 @@ export class AuthenticateController extends BaseController {
|
||||
const authToken = jwtTokenManager.createJWTToken(userUuid);
|
||||
res.writeStatus("200 OK");
|
||||
this.addCorsHeaders(res);
|
||||
res.end(JSON.stringify({
|
||||
authToken,
|
||||
userUuid,
|
||||
organizationSlug,
|
||||
worldSlug,
|
||||
roomSlug,
|
||||
mapUrlStart,
|
||||
organizationMemberToken,
|
||||
textures
|
||||
}));
|
||||
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
authToken,
|
||||
userUuid,
|
||||
organizationSlug,
|
||||
worldSlug,
|
||||
roomSlug,
|
||||
mapUrlStart,
|
||||
organizationMemberToken,
|
||||
textures,
|
||||
})
|
||||
);
|
||||
} catch (e) {
|
||||
this.errorToResponse(e, res);
|
||||
}
|
||||
|
||||
|
||||
})();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private verify(){
|
||||
private verify() {
|
||||
this.App.options("/verify", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
|
||||
@@ -82,50 +79,55 @@ export class AuthenticateController extends BaseController {
|
||||
const query = parse(req.getQuery());
|
||||
|
||||
res.onAborted(() => {
|
||||
console.warn('verify request was aborted');
|
||||
})
|
||||
console.warn("verify request was aborted");
|
||||
});
|
||||
|
||||
try {
|
||||
await jwtTokenManager.getUserUuidFromToken(query.token as string);
|
||||
} catch (e) {
|
||||
res.writeStatus("400 Bad Request");
|
||||
this.addCorsHeaders(res);
|
||||
res.end(JSON.stringify({
|
||||
"success": false,
|
||||
"message": "Invalid JWT token"
|
||||
}));
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
message: "Invalid JWT token",
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
res.writeStatus("200 OK");
|
||||
this.addCorsHeaders(res);
|
||||
res.end(JSON.stringify({
|
||||
"success": true
|
||||
}));
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
})
|
||||
);
|
||||
})();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//permit to login on application. Return token to connect on Websocket IO.
|
||||
private anonymLogin(){
|
||||
private anonymLogin() {
|
||||
this.App.options("/anonymLogin", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
res.end();
|
||||
});
|
||||
|
||||
this.App.post("/anonymLogin", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.App.post("/anonymLogin", (res: HttpResponse, req: HttpRequest) => {
|
||||
res.onAborted(() => {
|
||||
console.warn('Login request was aborted');
|
||||
})
|
||||
console.warn("Login request was aborted");
|
||||
});
|
||||
|
||||
const userUuid = v4();
|
||||
const authToken = jwtTokenManager.createJWTToken(userUuid);
|
||||
res.writeStatus("200 OK");
|
||||
this.addCorsHeaders(res);
|
||||
res.end(JSON.stringify({
|
||||
authToken,
|
||||
userUuid,
|
||||
}));
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
authToken,
|
||||
userUuid,
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user