1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +12:00
budibase/packages/worker/src/api/controllers/auth.js
Martin McKeaveney 9cebd859f8 merge
2021-04-15 16:49:35 +01:00

41 lines
863 B
JavaScript

const { passport, Cookies, clearCookie } = require("@budibase/auth")
exports.authenticate = async (ctx, next) => {
return passport.authenticate("local", async (err, user) => {
if (err) {
return ctx.throw(403, "Unauthorized")
}
const expires = new Date()
expires.setDate(expires.getDate() + 1)
if (!user) {
return ctx.throw(403, "Unauthorized")
}
ctx.cookies.set(Cookies.Auth, user.token, {
expires,
path: "/",
httpOnly: false,
overwrite: true,
})
delete user.token
ctx.body = { user }
})(ctx, next)
}
exports.logout = async ctx => {
clearCookie(ctx, Cookies.Auth)
ctx.body = { message: "User logged out" }
}
exports.googleAuth = async () => {
// return passport.authenticate("google")
}
exports.googleAuth = async () => {
// return passport.authenticate("google")
}