7f989cfd23
- Add all map json in back - Create middleware to check authentification user - Create controllers to get map - Create access to get all files in folder Assets/Maps
33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
import {Application, Request, Response} from "express";
|
|
import {BAD_REQUEST} from "http-status-codes";
|
|
import Jwt, {JsonWebTokenError} from "jsonwebtoken";
|
|
import {SECRET_KEY} from "../Enum/EnvironmentVariable";
|
|
|
|
export class AuthenticateMiddleware{
|
|
App: Application;
|
|
|
|
constructor(App: Application) {
|
|
this.App = App;
|
|
this.tokenVerification();
|
|
}
|
|
|
|
tokenVerification() {
|
|
this.App.use((req: Request, res: Response, next: any) => {
|
|
let token = req.header("Access-Token");
|
|
if (!token) {
|
|
return res.status(BAD_REQUEST).send({
|
|
message: "you must to be connected to get the map"
|
|
});
|
|
}
|
|
return Jwt.verify(token, SECRET_KEY, (err: JsonWebTokenError, tokenDecoded: object) => {
|
|
if (err) {
|
|
return res.status(BAD_REQUEST).send({
|
|
message: "you must to be connected to get the map"
|
|
});
|
|
}
|
|
return next();
|
|
});
|
|
})
|
|
}
|
|
}
|