Authenticating Communication
Explore how to implement WebSocket authentication within Redux by using token-based action dispatches. Understand integrating login tokens into the WebSocket middleware to manage authenticated sessions, handle login and logout flows, and prevent unauthorized communication before or after authentication.
We'll cover the following...
Handling authentication with WebSockets can be tricky, WebSockets are used alongside regular HTTP requests in many applications. The authentication will usually be done via regular REST or OAUTH calls. The front end will grant a token either set in cookies or saved in localStorage.
A special agreed-upon action has to be sent by the client to allow the server to authenticate a WebSocket. In Redux, a special action object can be serialized and sent before doing any other work over WebSockets.
Sample flow
A simple way to implement authentication might be to ...