Connectum API Reference / @connectum/auth / getAuthContext
Function: getAuthContext()
getAuthContext():
AuthContext|undefined
Defined in: packages/auth/src/context.ts:44
Get the current auth context.
Returns the AuthContext set by the auth interceptor in the current async context. Returns undefined if no auth interceptor is active or the current method was skipped.
Returns
AuthContext | undefined
Current auth context or undefined
Example
typescript
import { getAuthContext } from '@connectum/auth';
const handler = {
async getUser(req) {
const auth = getAuthContext();
if (!auth) throw new ConnectError('Not authenticated', Code.Unauthenticated);
return { user: await db.getUser(auth.subject) };
},
};