'How do I add a custom passport callback for every passport.authenticate function?

I am currently working on an account linking system, and I'm having trouble adding a custom callback function and url, I need atleast one of these to work. Please help.

The callback function doesn't run when I authorize my request, I've literally went to 100 threads about this, none of the seemed to fix this issue for me. My code is:

router.get("/link", async(req,res, next) => {
    console.log("1/2")
    passport.authenticate("discord", {}, function(err, user, info) {
        console.log("2/2")
        if (err) { return next(err); }
        if (!user) { return res.redirect('/login'); }
    })(req, res)
    console.log("test")
})

Only the "1/2" and "test" logs, the "2/2" doesn't log. Which means that the function doesn't run.

And also, is there a way to change the callback url when you use the function, for example in the options i set {callbackUrl:"..."} or something similar, as that would be great too, I haven't been able to find any resource about this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source