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);
|
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();
|
const session = await auth();
|
||||||
|
|
||||||
if(!session) {
|
if(!session) {
|
||||||
return({
|
throw new Error("Not authenticated")
|
||||||
errors: {
|
|
||||||
message: "Not authenticated",
|
|
||||||
},
|
|
||||||
message: "Not authenticated",
|
|
||||||
} as AuthErrorMessage);
|
|
||||||
}
|
}
|
||||||
const { user } = session;
|
const { user } = session;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user