Skip to content

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.

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 };
},
});
const client = createZocketClient<AppRouter>("ws://localhost:3000", {
headers: { token: "user-session-token" },
});