deno.land / x / pothos@release-1713397530 / packages / plugin-scope-auth / schema-builder.ts
12345678910111213141516171819202122232425262728// @ts-nocheckimport SchemaBuilder, { isThenable, MaybePromise, SchemaTypes } from '../core/index.ts';import { ForbiddenError } from './errors.ts';import RequestCache from './request-cache.ts';import { AuthFailure } from './types.ts';const schemaBuilderProto = SchemaBuilder.prototype as PothosSchemaTypes.SchemaBuilder<SchemaTypes>;// eslint-disable-next-line consistent-returnschemaBuilderProto.runAuthScopes = function runAuthScopes(context, scopes, unauthorizedError = (result) => new ForbiddenError(result.message, result.failure)): MaybePromise<void> { const cache = RequestCache.fromContext(context, this); const resultOrPromise = cache.evaluateScopeMap(scopes); if (isThenable(resultOrPromise)) { return resultOrPromise.then(handleScopeResult); } handleScopeResult(resultOrPromise); function handleScopeResult(result: AuthFailure | null) { if (result) { const error = unauthorizedError({ message: "Unauthorized", failure: result, }); if (typeof error === "string") { throw new ForbiddenError(error, result); } throw error; } }};
Version Info