From 5dfe86a328c4cb0c26007a21cdc91c528c75871c Mon Sep 17 00:00:00 2001 From: Daniel Adu-Gyan <26229521+danieladugyan@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:37:12 +0200 Subject: [PATCH] Fix type signature of auth check functions --- src/lib/utils/authorization.ts | 10 ++++++++-- src/routes/(app)/admin/debug/+page.svelte | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/utils/authorization.ts b/src/lib/utils/authorization.ts index 120dfcaea..41f13d20b 100644 --- a/src/lib/utils/authorization.ts +++ b/src/lib/utils/authorization.ts @@ -7,7 +7,10 @@ import * as m from "$paraglide/messages"; * Check if the user is authorized to perform an action. * @returns Whether the user is authorized. */ -export const isAuthorized = (apiName: string, user?: AuthUser): boolean => { +export const isAuthorized = ( + apiName: string, + user: AuthUser | undefined, +): boolean => { if (dev && !!user?.studentId) return true; if (user?.policies.includes(apiName)) return true; return false; @@ -17,7 +20,10 @@ export const isAuthorized = (apiName: string, user?: AuthUser): boolean => { * Authorize a user to perform an action or a list of actions. * @throws {HttpError} If the user is not authorized. */ -export const authorize = (apiName: string | string[], user?: AuthUser) => { +export const authorize = ( + apiName: string | string[], + user: AuthUser | undefined, +) => { const apiNames = Array.isArray(apiName) ? apiName : [apiName]; for (const name of apiNames) { if (!isAuthorized(name, user)) { diff --git a/src/routes/(app)/admin/debug/+page.svelte b/src/routes/(app)/admin/debug/+page.svelte index 7737213cf..dc99a4dd8 100644 --- a/src/routes/(app)/admin/debug/+page.svelte +++ b/src/routes/(app)/admin/debug/+page.svelte @@ -1,5 +1,6 @@ -{#if isAuthorized("core:admin")} +{#if isAuthorized("core:admin", $page.data.user)}

Actions