From c7b4829d035fb603571d2f1cbf832ae98b8a7718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Tue, 9 Jan 2024 14:39:17 +0100 Subject: [PATCH] withUser throws an error if the user is not authenticated --- app/lib/auth.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/lib/auth.ts b/app/lib/auth.ts index d616894..a32437f 100644 --- a/app/lib/auth.ts +++ b/app/lib/auth.ts @@ -59,16 +59,11 @@ export const isAuthErrorMessage = (obj: any): obj is AuthErrorMessage => { return (obj.message && obj.errors && obj.errors.message); } -export const withUser = (fn: (user: AuthenticatedUser, ...args:any) => Promise) => async (...args:any) => { +export const withUser = (fn: (user: AuthenticatedUser, ...args:A) => Promise) => async (...args:A) => { const session = await auth(); if(!session) { - return({ - errors: { - message: "Not authenticated", - }, - message: "Not authenticated", - } as AuthErrorMessage); + throw new Error("Not authenticated") } const { user } = session;