You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
341 B
JavaScript

import { UserStore } from "../db/schemas.mjs";
export const auth = async (req, res, next) => {
const accessToken = req.headers['access-token'];
res.locals.user = await UserStore.findOne().byAccessToken(accessToken);
if (!res.locals.user) {
res.status(401);
res.send({ message: 'unauthorized' });
return;
}
next();
};