(fn: (params: RequiredAuthContext) => Promise<T>)
| 30 | |
| 31 | |
| 32 | export const withAuth = async <T>(fn: (params: RequiredAuthContext) => Promise<T>) => { |
| 33 | const authContext = await getAuthContext(); |
| 34 | |
| 35 | if (isServiceError(authContext)) { |
| 36 | return authContext; |
| 37 | } |
| 38 | |
| 39 | const { user, org, role, prisma } = authContext; |
| 40 | |
| 41 | if (!user || !role) { |
| 42 | return notAuthenticated(); |
| 43 | } |
| 44 | |
| 45 | return fn({ user, org, role, prisma }); |
| 46 | }; |
| 47 | |
| 48 | export const withOptionalAuth = async <T>(fn: (params: OptionalAuthContext) => Promise<T>) => { |
| 49 | const authContext = await getAuthContext(); |
no test coverage detected