mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add missing file
This commit is contained in:
parent
a4e707075f
commit
db3d7dca36
1 changed files with 26 additions and 0 deletions
26
packages/api/src/utils/gql-utils.ts
Normal file
26
packages/api/src/utils/gql-utils.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { ResolverFn } from '../generated/graphql'
|
||||
import { Claims, WithDataSourcesContext } from '../resolvers/types'
|
||||
|
||||
export function authorized<
|
||||
TSuccess,
|
||||
TError extends { errorCodes: string[] },
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
TArgs = any,
|
||||
TParent = any
|
||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||
>(
|
||||
resolver: ResolverFn<
|
||||
TSuccess | TError,
|
||||
TParent,
|
||||
WithDataSourcesContext & { claims: Claims },
|
||||
TArgs
|
||||
>
|
||||
): ResolverFn<TSuccess | TError, TParent, WithDataSourcesContext, TArgs> {
|
||||
return (parent, args, ctx, info) => {
|
||||
const { claims } = ctx
|
||||
if (claims?.uid) {
|
||||
return resolver(parent, args, { ...ctx, claims, uid: claims.uid }, info)
|
||||
}
|
||||
return { errorCodes: ['UNAUTHORIZED'] } as TError
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue