withUser throws an error if the user is not authenticated
This commit is contained in:
@@ -59,16 +59,11 @@ export const isAuthErrorMessage = (obj: any): obj is AuthErrorMessage => {
|
||||
return (obj.message && obj.errors && obj.errors.message);
|
||||
}
|
||||
|
||||
export const withUser = <T>(fn: (user: AuthenticatedUser, ...args:any) => Promise<T>) => async (...args:any) => {
|
||||
export const withUser = <T, A extends any[]>(fn: (user: AuthenticatedUser, ...args:A) => Promise<T>) => 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user