So I want to make authentication so that a user can authenticate by twitter and discord. So I created developer accounts in twitter and discord developer portal. then I made passport strategy for both socials. For reference I am providing my strategy credentials in the following(for twitter):
{
consumerKey: process.env.TWITTER_CONSUMER_KEY,
consumerSecret: process.env.TWITTER_CONSUMER_SECRET,
callbackURL: "http://localhost:9000/api/auth/twitter/callback",
includeEmail: true,
}
the discord one is similar to twitter.
Routes for twitter are:
router.get("/auth/discord", passport.authenticate("discord"))
router.get(
"/auth/discord/redirect",
passport.authenticate("discord"),
(req, res) => {
res.json({
success: true,
user: req.user,
})
}
)
Now my question is after a user authorizes, how can I redirect the user to SPA route (React/Vue)?
2
Answers
That was very simple indeed. I just needed to add redirect to my frontend url
As I can see in the passport.js documentation, there are two parameters available when you call
passport.authenticate
function. These two are:successRedirect
andfailureRedirect
.Check this out 😉 passportjs.org/tutorials/auth0/routes