authExtension()
authExtension<
Ctx
>(loadScopes
,options
): () =>Extension
Creates an authentication extension.
Type Parameters
Type Parameter |
---|
|
Parameters
Parameter | Type | Description |
---|---|---|
|
|
Function to load authorization scopes |
|
Configuration options for the auth extension |
Returns
A factory function that creates an AuthExtension instance
():
Extension
Returns
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 } },
},
},
);