© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Imran Khan
Software Developer
Hello Everyone,
Is there any good example I could follow for passport-twitter npm package with nextjs. I am working on a project and could be great helpful.
Thank you.
This is where I got stuck actually.
"/twitter", passport.authenticate("twitter", { scope: ["profile"] }));
"/twitter/callback", passport.authenticate("twitter", { failureRedirect: "/login" }), controllers.authController.twitter_callback );
twitter_callback: async (req, res) => { try { const twitter_user = await req.user; const user = await User.create({ name: twitter_user.displayName, email: twitter_user.emails[0].value }); const token = user.generateAuthToken(); res.header("x_auth_token", token).json({ msg: "callback called", status: 200 }); // res.redirect("/"); } catch (err) { console.log(err); // res.status(500).json(err); } }
I'm having trouble with saving the header token in cookie. I need to store the header token in cookie.
Diego Bernal
Front-End Engineer
Store it like this
Then, you can read it in getInitialProps with next-cookies
getInitialProps
Thanks Diego, had to use cookie-parser
Imran Khan
Software Developer
This is where I got stuck actually.
"/twitter", passport.authenticate("twitter", { scope: ["profile"] }));"/twitter/callback", passport.authenticate("twitter", { failureRedirect: "/login" }), controllers.authController.twitter_callback );twitter_callback: async (req, res) => { try { const twitter_user = await req.user; const user = await User.create({ name: twitter_user.displayName, email: twitter_user.emails[0].value }); const token = user.generateAuthToken(); res.header("x_auth_token", token).json({ msg: "callback called", status: 200 }); // res.redirect("/"); } catch (err) { console.log(err); // res.status(500).json(err); } }I'm having trouble with saving the header token in cookie. I need to store the header token in cookie.