Effect CommunityEC
Effect Community2y ago
13 replies
ohdearlordylord

experimental/SocketServer authentication data

@effect/experimental/SocketServer/Node: do I get it right that there's no way to authenticate from initial connection headers (Authorization: Bearer ...) and pass the result (e.g. my userId) into further computation ?

Effect.gen(function* () {
  const server = yield* SocketServer.SocketServer;
  yield* server.run((socket) => Effect.gen(function* () {
    // socket is authenticated at this point
  }))
});


const verifyClient: VerifyClientCallbackSync = ({origin, req, secure}) => {
  // can do stuff here with req.headers but can't pass data to socket
  return true;
}
const webSocketLayer = layerWebSocket({
  port: 3004,
  verifyClient,
});


(I'm currently overcoming it with message-based authentication process after socket is already connected)
Was this page helpful?