'Passport Session resets after redirect?
I'm trying to create a react app with socketio and oauth(passport-spotify) in the backend, but I can't access user information in socketIO after successful authorization and redirection.
I put the barebone project on github here https://github.com/Agonyagonyagony/PassportSocketIOAuth
passport.use(
new SpotifyStrategy(
{
clientID: process.env.SPOTIFY_CLIENT_ID,
clientSecret: process.env.SPOTIFY_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/spotify/callback",
passReqToCallback: true,
},
function (req, accessToken, refreshToken, expires_in, profile, done) {
const user = profile;
done(null, user);
}
)
);
[...]
app.get(
"/auth/spotify/callback",
passport.authenticate("spotify", { failureRedirect: "/login" }),
function (req, res) {
console.log(req.session);
// console.log(req.session.cookie);
// Successful authentication, redirect home.
// // res.cookie("connect.sid", JSON.stringify(req.session.cookie));
res.redirect("/");
}
);
[...]
io.on("connection", (socket: Socket) => {
console.log("socket initialization completed");
console.log(socket.request.user ?? "none");
console.log(socket.request.passport ?? "none");
socket.on("say", (data) => {
console.log(data, "received information");
socket.emit("message", { hello: "who are you" });
});
});
The callback function gets the profile information, but the redirect to my frontend seems to reset the session? I tried serving a simple html with socketio within express and that worked, but that's not really an option for development.
I also tried writing cookies with the redirect. That showed a cookie, but the io connection didn't seem to care.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
