uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.85k stars 569 forks source link

How to detect URI on websocket connect #466

Closed be-thomas closed 3 years ago

be-thomas commented 3 years ago

I need a way to authenticate users. I want to disconnect a user immediately on connect based on query parameters.

This can be done in node express-ws library, it can be done by handling the on-upgrade handler -

[https://stackoverflow.com/questions/59070321/websockets-token-authentication-using-middleware-and-express-in-node-js/59314360#59314360](Node Websocket Auth).

A code snippet would be great

hst-m commented 3 years ago

https://github.com/uNetworking/uWebSockets.js/discussions/339#discussioncomment-172632

ramiroaisen commented 3 years ago

You just have to pass the upgrade(res, req, ctx) function to app.ws()