Authentication (v1)
This documents the old v1 API. See Authentication for the current version.
Authentication happens during the initial connection handshake. Headers are sent as URL query parameters.
Server Side
Section titled “Server Side”const zo = zocket.create({ headers: z.object({ token: z.string() }), onConnect: async (headers) => { const user = await verifyToken(headers.token); if (!user) return { user: null }; return { user }; },});Client Side
Section titled “Client Side”const client = createZocketClient<AppRouter>("ws://localhost:3000", { headers: { token: "user-session-token" },});