Skip to content
Snippets Groups Projects
Commit 0b1dff35 authored by Renzo Beux's avatar Renzo Beux
Browse files

hotfix

parent 4c285403
No related branches found
No related tags found
No related merge requests found
......@@ -2,15 +2,15 @@ import { Response, NextFunction } from 'express';
import { validate } from '../Services/UserAPI';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const authChecker = (req: any, res: Response, next: NextFunction): void => {
const token = req.headers.authorization;
const userId = validate(token);
if (userId === -1) {
const authChecker = async (req: any, res: Response, next: NextFunction): void => {
try {
const token = req.headers.authorization;
const userId = await validate(token);
req.user_id = userId;
next();
} catch (error) {
res.status(401).send({ message: 'auth failed' });
return;
}
req.user_id = userId;
next();
};
export default authChecker;
......@@ -11,16 +11,8 @@ const instance = axios.create({
baseURL: process.env.AUTH_BASE_URL,
});
export const validate = (token: string): number => {
let id = -1;
instance.post('/validate', { token })
.then((res) => {
id = (res.data as any).userId as number;
})
.catch((err) => {
throw (err);
// if needed implement later
});
export const validate = async (token: string) => {
const id = await instance.post('/validate', { token });
return id;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment