Skip to main content

GetScopeLoader()<Scopes, Ctx>

GetScopeLoader<Scopes, Ctx> = (ctx) => ScopeLoaderMap<Scopes> | Promise<ScopeLoaderMap<Scopes>>

Function that creates scope loaders for authorization checks. Returns a map of scope loaders that can be synchronous or asynchronous.

Type Parameters

Type Parameter

Scopes extends ScopesShape

Ctx

Parameters

ParameterTypeDescription

ctx

Ctx

The application context

Returns

ScopeLoaderMap<Scopes> | Promise<ScopeLoaderMap<Scopes>>

A map of scope loaders or a promise resolving to scope loaders

Example

const getScopeLoader: GetScopeLoader<Context> = (ctx) => ({
isLoggedIn: async () => {
if (!ctx.userId) throw new UnauthenticatedError();
return true;
},
hasAccess: (role) => ctx.user?.role === role,
});