Files
maestro/src/middlewares/authentication.ts
T
2022-02-04 10:03:55 -03:00

31 lines
732 B
TypeScript

import { Request, Response, NextFunction } from 'express';
import axios from 'axios';
import { NestMiddleware } from '@nestjs/common';
export class LoggerMiddleware implements NestMiddleware{
use = async (
request: Request,
response: Response,
next: NextFunction
) => {
try {
const verify_response = await axios.post(
`${process.env.DEV_URL}/user/verify`,
{ "token":request.get('Authorization')}
).then(response =>{
if(response.data.message == "Success"){
next()
}
})
} catch (error) {
response.status(401).send({ message: 'Authentication Failed!' });
}
};
}