Files
forgetmenot-nextjs/web/lib/apiHelpers.js
2022-07-05 21:15:42 -05:00

28 lines
555 B
JavaScript

import auth0 from "./auth0";
function withErrorHandling(handler) {
return async (req, res) => {
try {
await handler(req, res);
} catch (error) {
console.error(error);
res.status(error.status || 500).end(error.message);
}
};
}
function withSession(handler) {
return async (req, res) => {
const session = await auth0.getSession(req, res);
if (!session || !session.user) {
res.status(401).end();
return;
}
await handler(req, res, session);
}
}
export { withErrorHandling, withSession };