diff --git a/api/src/middleware/authz.middleware.ts b/api/src/middleware/authz.middleware.ts index 552e360..b180dcc 100644 --- a/api/src/middleware/authz.middleware.ts +++ b/api/src/middleware/authz.middleware.ts @@ -84,7 +84,7 @@ export async function loadUser(req: Request, res: Response, next: NextFunction) }; await db.create(newUser); - req.user = { ...req.user, ...newUser }; + req.user = { ...req.user, ...newUser, roles: [] }; } } else { console.log("Payload from Auth0 is strange or failed for", req.auth); diff --git a/api/src/services/user-service.ts b/api/src/services/user-service.ts index 63c3e3e..6a8b5e6 100644 --- a/api/src/services/user-service.ts +++ b/api/src/services/user-service.ts @@ -1,5 +1,6 @@ import { User } from "../data/models"; import { db } from "../data"; +import { isArray } from "lodash"; export class UserService { async getAll(): Promise { @@ -8,6 +9,11 @@ export class UserService { async getBySub(auth_subject: string): Promise { let user = await db("users").where({ auth_subject }).first(); + + if (user && user.roles) { + if (!isArray(user.roles)) user.roles = user.roles.split(","); + } + return user; } @@ -15,12 +21,21 @@ export class UserService { let user = await db("users") .where({ id: parseInt(`${id}`) }) .first(); + + if (user && user.roles) { + if (!isArray(user.roles)) user.roles = user.roles.split(","); + } return user; } async getByEmail(email: string): Promise { if (email) { let user = await db("users").where({ email }).first(); + + if (user && user.roles) { + if (!isArray(user.roles)) user.roles = user.roles.split(","); + } + return user; } diff --git a/web/src/layouts/DefaultNoAuth.vue b/web/src/layouts/DefaultNoAuth.vue index 812c53d..d8370a5 100644 --- a/web/src/layouts/DefaultNoAuth.vue +++ b/web/src/layouts/DefaultNoAuth.vue @@ -64,22 +64,14 @@