1

I am creating login with facebook using passport-facebook.Inside function(accessToken, refreshToken, profile, cb){ } I am checking email(provided by facebook) against users table . If user found, I simply set session but if user is not found in users table, I want to redirect user to register page with data provided by facebook. Can anyone please help me with the same? I followed this question's answer but not able to use res.redirect(), getting error

error err_http_headers_sent cannot set headers after they are sent to the client

Devil10
  • 1,853
  • 1
  • 18
  • 22
Irphan
  • 53
  • 1
  • 9

1 Answers1

1

you should try

// Username does not exist, log error & redirect back
        if (!user){
          console.log('User Not Found with username '+username);
          return done(null, false, 
                res.redirect('/registerationpage'));                 
        }

for detail explanation try this post:

https://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport--cms-21619 .

It helps with algorithm and logic also with the examples.

just coding
  • 173
  • 13
  • getting same error after using above code `UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client` – Irphan Aug 17 '18 at 09:08
  • can you create a code snippet or jsfiddle. because you get such errors with the express.js https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client – just coding Aug 17 '18 at 09:48
  • https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client try this then – just coding Aug 17 '18 at 10:04