2020-04-23 15:37:08 +02:00
|
|
|
const jwt = require("jsonwebtoken");
|
|
|
|
|
|
|
|
module.exports = async (ctx, next) => {
|
2020-05-06 21:29:47 +02:00
|
|
|
const token = ctx.cookies.get("budibase:token");
|
|
|
|
console.log("TOKEN", token);
|
|
|
|
|
|
|
|
if (!token) {
|
2020-05-04 18:13:57 +02:00
|
|
|
ctx.isAuthenticated = false
|
|
|
|
await next();
|
|
|
|
return;
|
|
|
|
};
|
2020-04-23 15:37:08 +02:00
|
|
|
|
|
|
|
try {
|
2020-05-06 21:29:47 +02:00
|
|
|
ctx.jwtPayload = jwt.verify(token, ctx.config.jwtSecret);
|
2020-05-04 18:13:57 +02:00
|
|
|
ctx.isAuthenticated = true;
|
2020-04-23 15:37:08 +02:00
|
|
|
} catch (err) {
|
|
|
|
ctx.throw(err.status || 403, err.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
await next();
|
|
|
|
};
|