Add info to 403 responses

This commit is contained in:
Rory Powell 2021-07-07 13:28:55 +01:00
parent 71ddd41877
commit c15051462e
1 changed files with 5 additions and 5 deletions

View File

@ -11,16 +11,16 @@ const { checkResetPasswordCode } = require("../../../utilities/redis")
const GLOBAL_DB = authPkg.StaticDatabases.GLOBAL.name
function authInternal(ctx, user, err = null) {
function authInternal(ctx, user, err = null, info = null) {
if (err) {
return ctx.throw(403, "Unauthorized")
return ctx.throw(403, info? info : "Unauthorized")
}
const expires = new Date()
expires.setDate(expires.getDate() + 1)
if (!user) {
return ctx.throw(403, "Unauthorized")
return ctx.throw(403, info? info : "Unauthorized")
}
ctx.cookies.set(Cookies.Auth, user.token, {
@ -154,8 +154,8 @@ exports.oidcAuth = async (ctx, next) => {
return passport.authenticate(
strategy,
{ successRedirect: "/", failureRedirect: "/error" },
async (err, user) => {
authInternal(ctx, user, err)
async (err, user, info) => {
authInternal(ctx, user, err, info)
ctx.redirect("/")
}