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

validate method

parent 75416d22
No related branches found
No related tags found
No related merge requests found
......@@ -140,12 +140,31 @@ const login = async (req: Request, res: Response): Promise<Response> => {
}
};
const validate = async (req: Request, res: Response): Promise<Response> => {
const { token } = req.body;
if (token) {
jwt.verify(token, secret.auth, (error: Error, decoded: {id: number; type: number}) => {
if (error) {
const message = 'Invalid token';
return res.status(401).send({ message });
}
const userId = decoded.id;
return res.status(200).send({ userId });
});
} else {
return res.status(400).send('auth token not supplied');
}
return res.status(500).send();
};
router.route('/login')
.post(login);
router.route('/')
.post(create);
router.validate('/validate', validate);
router.use('/', authorized);
router.route('/')
......
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