Skip to content
On this page

Socket Middleware

The socket middleware should be injected at the beginning of the chain.

Besides, validating the authorization header, the createSocketMiddleware also extends the request with general information (realm, abilities, ...) and information about the corresponding robot or user of the token.


The createSocketMiddleware method, accepts a configuration object. The redis client, if enabled, is used to cache verification responses from the backend service.

import { Server } from '';
import { createSocketMiddleware } from '@authup/server-adapter';
import { createClient } from 'redis-extension';

// create redis client
const redis = createClient({connectionString: 'redis://'});

// setup server
const server = new Server();

// setup socket middleware for socket server
    tokenByCookie: (req, cookieName) => req.cookies[cookieName],
    tokenVerifier: {
        baseURL: 'http://localhost:3010/',
        creator: {
            type: 'user',
            name: 'admin',
            password: 'start123',
        cache: {
            type: 'redis',
            client: redis
    tokenVerifierHandler: (req, data) => {
        // { 'realmId': 'xxx', userId: 'xxx', userName: 'xxx', ... }
    /* ... */

// ...

For more details check out, the API Reference.