with socket io
# bot-training
r
How can I use supertokens with socket io?
To use SuperTokens with Socket.IO, you can initiate the socket connection with an HTTP call which uses
verifySession
as usual. During each event fire, you can authenticate the user in two ways: 1. Enable JWTs in the session recipe, and then access JWT on the frontend using
await Session.getAccessTokenPayloadSecurely().jwt
, which you can send for each socket event and verify that on the backend. 2. Send the session's sessionHandle to the frontend and send that on each socket event. You can then query the SuperTokens core to get info (like the userID) from the session handle. Method 1 is much faster since it's stateless verification, but method 2 is more secure since revoking a session will terminate the socket connection auth immediately.
st-bot-test-case
5 Views