A few more api call basics

This commit is contained in:
2022-07-05 21:15:42 -05:00
parent 2fa58305cb
commit d1495df5a1
4 changed files with 108 additions and 39 deletions

View File

@@ -1,3 +1,5 @@
import auth0 from "./auth0";
function withErrorHandling(handler) {
return async (req, res) => {
try {
@@ -9,4 +11,17 @@ function withErrorHandling(handler) {
};
}
export { withErrorHandling };
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 };