1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00
budibase/packages/server/middleware/authenticated.js
Martin McKeaveney 8f5845943a Auth working
2020-05-06 20:29:55 +01:00

21 lines
No EOL
432 B
JavaScript

const jwt = require("jsonwebtoken");
module.exports = async (ctx, next) => {
const token = ctx.cookies.get("budibase:token");
console.log("TOKEN", token);
if (!token) {
ctx.isAuthenticated = false
await next();
return;
};
try {
ctx.jwtPayload = jwt.verify(token, ctx.config.jwtSecret);
ctx.isAuthenticated = true;
} catch (err) {
ctx.throw(err.status || 403, err.text);
}
await next();
};