retropilot-server/src/server/middlewares/authentication.js

24 lines
568 B
JavaScript
Raw Normal View History

2022-03-22 07:03:17 -06:00
import authenticationController from '../controllers/authentication';
2022-03-22 09:14:08 -06:00
export const getAccount = async (req, res, next) => {
req.account = await authenticationController.getAuthenticatedAccount(req);
next();
};
export const requireAuthenticated = async (req, res, next) => {
2022-03-22 07:03:17 -06:00
const account = await authenticationController.getAuthenticatedAccount(req);
console.log(account);
2022-03-22 07:03:17 -06:00
if (!account) {
res.status(401).json({
success: false,
code: 'NOT_AUTHENTICATED',
});
return;
}
req.account = account;
2022-03-22 07:03:17 -06:00
next();
};
export default null;