Search code examples
node.jstypescriptexpresspassport.jspassport-facebook

Passport Authentication Redirection to absolute URL fails


I want to redirect the request to another URL alongwith the code / token received from the logging into the facebook via passport in express js.

app.get('/auth/facebook/callback', function (req, res, next) {
    var authenticator = passport.authenticate('facebook', {
        successRedirect: "http://localhost:3200/#/home/",
        failureRedirect: '/'
    });

The problem is it dont redirect to the url specified alongwith the code in query so i can manage the state in angular app also.


Solution

  • You should put passport.authenticate instead of function (req, res, next):

    app.get('/auth/facebook/callback', passport.authenticate('facebook', {
        successRedirect: "http://localhost:3200/#/home/",
        failureRedirect: '/'
    }));