A few more api call basics
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user