Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook login state missing #53

Open
Revln9 opened this issue Nov 5, 2016 · 3 comments
Open

Facebook login state missing #53

Revln9 opened this issue Nov 5, 2016 · 3 comments

Comments

@Revln9
Copy link

Revln9 commented Nov 5, 2016

Hi , first of all good job , nice clean work !

Can you please tell me if you tested the facebook login feature?

I tried to login via facebook and after facebook login callback is called , the state doesn't change .

i digged a bit the question and found out that on the server side a couple of lines were missing.

React-cookie form what i could read uses the cookie parser middleware of express which is not even installed

then you have to call reactCookie.plugToRequest(req, res); to attach cookies to the requests and responses

do you think that this is the best thing to do in this case? or should i wire it up directly to global variable used in index.html

Thanks

@raineroviir
Copy link
Owner

Hi Revin, Thanks!

I know that the FB login is not working properly atm. It's up to you on how you want to store the token, and cookies are fine.

@Revln9
Copy link
Author

Revln9 commented Nov 5, 2016

Ok thanks , i'm working on it , i'll post it once its done

@Revln9
Copy link
Author

Revln9 commented Nov 6, 2016

Got it working with the cookie-parser

First install Cookie-parser

npm install -s cookie-parser

at config/passport.js remove all react cookie and cookies.save methods

at server.dev.js add app.use(cookieParser());

at routes/user_routes.js replace the route that listen to the facebook callback

so instead of this

router.get('/auth/facebook/callback', passport.authenticate('facebook', { session: false, successRedirect: '/chat', failureRedirect: '/' }));

do this :

router.get('/auth/facebook/callback', function(req, res, next) {
  passport.authenticate('facebook', function(err, user, info) {
    if (err) { return next(err); }
    if (!user) { return res.redirect('/login'); }
res.cookie('username', user.facebook.username, { maxAge: 900000, httpOnly: true });
res.redirect('/chat')
  })(req, res, next);
});

and finally at server.dev.js

replace


    const initialState = {
      auth: {
        user: {
          username: 'tester123',
          id: 0,
          socketID: null
        }
      }
    }

by this 👍


    let initialState = {};

  if(!req.cookies.username){
   let username = 'Guest'
 initialState = {
      auth: {
        user: {
          username: username,
          id: 0,
          socketID: null
        }
      }
    }
  }

  if(req.cookies.username) {
      let username = req.cookies.username || 'Guest'
      initialState = {
      auth: {
        user: {
          username:username,
          socketID: null
        }
      }
    }
  }

not the optimal move , since we could leverage the express session or put the token on the header but definitely works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants