Skip to content

How to get authenticated user details in socket.io with passport.js ? Why user is undefined in socket.request.user ? #4470

Answered by darrachequesne
rigan-dev asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! Did you set withCredentials to true on the client-side, in order to include the cookies in the cross-site requests?

import { io } from "socket.io-client";

const socket = io("https://my-backend.com", {
  withCredentials: true
});

Reference: https://socket.io/docs/v4/client-options/#withcredentials

You can also check:

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@TheSamDickey
Comment options

Answer selected by darrachequesne
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@darrachequesne
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants