Skip to main content

authExtension()

authExtension<Ctx>(loadScopes, options): () => Extension

Creates an authentication extension.

Type Parameters

Type Parameter

Ctx

Parameters

ParameterTypeDescription

loadScopes

GetScopeLoader<Scopes, Ctx>

Function to load authorization scopes

options

AuthOptions

Configuration options for the auth extension

Returns

A factory function that creates an AuthExtension instance

(): Extension

Returns

Extension

Example

const authExt = authExtension<Context>(
async (ctx) => ({
isLoggedIn: () => ctx.userId != null,
hasRole: (role) => ctx.user?.role === role,
}),
{
defaultScopes: {
Query: { isLoggedIn: true },
Mutation: { isLoggedIn: true },
Subscription: { subscribe: { isLoggedIn: true } },
},
},
);