Connectum API Reference / @connectum/auth / createSessionAuthInterceptor
Function: createSessionAuthInterceptor() ​
createSessionAuthInterceptor(
options):Interceptor
Defined in: packages/auth/src/session-auth-interceptor.ts:70
Create a session-based authentication interceptor.
Two-step authentication:
- Extract token from request
- Verify session via user-provided callback (receives full headers for cookie support)
- Map session data to AuthContext via user-provided mapper
A ConnectError thrown by verifySession or mapSession reaches the client unchanged (code and message), so choose its text as public. Any other thrown value is replaced by Unauthenticated: Session verification failed / Session mapping failed.
Parameters ​
options ​
Session auth configuration
Returns ​
Interceptor
ConnectRPC interceptor
Throws ​
When verifySession or mapSession is not a function, or extractToken is set and is not a function
Throws ​
When skipMethods contains "*"
Throws ​
When cache has a ttl that is not finite and positive, or a maxSize that is not an integer of at least 1
Example ​
better-auth integration
import { createSessionAuthInterceptor } from '@connectum/auth';
const sessionAuth = createSessionAuthInterceptor({
verifySession: (token, headers) => auth.api.getSession({ headers }),
mapSession: (s) => ({
subject: s.user.id,
name: s.user.name,
roles: [],
scopes: [],
claims: s.user,
type: 'session',
}),
cache: { ttl: 60_000 },
});