1
0
Fork 0
mirror of synced 2024-06-29 19:41:03 +12:00
budibase/packages/auth/src/middleware/authenticated.js

19 lines
409 B
JavaScript
Raw Normal View History

2021-04-11 22:35:55 +12:00
const { Cookies } = require("../constants")
const { getCookie } = require("../utils")
2021-04-11 22:35:55 +12:00
module.exports = async (ctx, next) => {
try {
// check the actual user is authenticated first
const authCookie = getCookie(ctx, Cookies.Auth)
2021-04-11 22:35:55 +12:00
if (authCookie) {
ctx.isAuthenticated = true
ctx.user = authCookie
2021-04-11 22:35:55 +12:00
}
await next()
} catch (err) {
ctx.throw(err.status || 403, err)
2021-04-11 22:35:55 +12:00
}
}