From 2cb8b45fcfefa8e6f6a4ba658c311e975bda5dca Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 3 Jul 2023 16:40:21 +0200 Subject: [PATCH] Update backend/src/graphql/directive/isAuthorized.ts Co-authored-by: Hannes Heine --- backend/src/graphql/directive/isAuthorized.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/directive/isAuthorized.ts b/backend/src/graphql/directive/isAuthorized.ts index 660806d3d..20efb0cb9 100644 --- a/backend/src/graphql/directive/isAuthorized.ts +++ b/backend/src/graphql/directive/isAuthorized.ts @@ -37,14 +37,18 @@ export const isAuthorized: AuthChecker = async ({ context }, rights) => }) // console.log('isAuthorized user=', user) context.user = user + context.role = ROLE_USER if (user.userRoles && user.userRoles.length > 0) { - if (user.userRoles[0].role === ROLE_NAMES.ROLE_NAME_ADMIN) { - context.role = ROLE_ADMIN - } else if (user.userRoles[0].role === ROLE_NAMES.ROLE_NAME_MODERATOR) { - context.role = ROLE_MODERATOR + switch (user.userRoles[0].role) { + case ROLE_NAMES.ROLE_NAME_ADMIN: + context.role = ROLE_ADMIN + break + case ROLE_NAMES.ROLE_NAME_MODERATOR: + context.role = ROLE_MODERATOR + break + default: + context.role = ROLE_USER } - } else { - context.role = ROLE_USER } // console.log('context.role=', context.role) } catch {