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'; ...@@ -2,15 +2,15 @@ import { Response, NextFunction } from 'express';
import { validate } from '../Services/UserAPI'; import { validate } from '../Services/UserAPI';
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
const authChecker = (req: any, res: Response, next: NextFunction): void => { const authChecker = async (req: any, res: Response, next: NextFunction): void => {
const token = req.headers.authorization; try {
const userId = validate(token); const token = req.headers.authorization;
if (userId === -1) { const userId = await validate(token);
req.user_id = userId;
next();
} catch (error) {
res.status(401).send({ message: 'auth failed' }); res.status(401).send({ message: 'auth failed' });
return;
} }
req.user_id = userId;
next();
}; };
export default authChecker; export default authChecker;
...@@ -11,16 +11,8 @@ const instance = axios.create({ ...@@ -11,16 +11,8 @@ const instance = axios.create({
baseURL: process.env.AUTH_BASE_URL, baseURL: process.env.AUTH_BASE_URL,
}); });
export const validate = (token: string): number => { export const validate = async (token: string) => {
let id = -1; const id = await instance.post('/validate', { token });
instance.post('/validate', { token })
.then((res) => {
id = (res.data as any).userId as number;
})
.catch((err) => {
throw (err);
// if needed implement later
});
return id; 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