sahat / megaboilerplate

Handcrafted starter projects, optimized for simplicity and ease of use.
MIT License
3.83k stars 257 forks source link

Account linking does not work under React #148

Closed maael closed 8 years ago

maael commented 8 years ago

Behaviour

When you try to link two accounts in a project generated with the react js framework, a new account is made instead.

Background

This seems to be done because the req.isAuthenticated() call at https://git.io/vKTk6 fails, and https://git.io/vKTk1 will also fail to find a user as this is the first time the account for the chosen service has been seen, so a new account is made.

It appears that https://git.io/vKTkN has the token set as undefined, as the token can't be found in the cookies at that point for some reason.

Expected Behaviour

It would be expected that req.isAuthenticated() check should pass, and the new service added the user on the req, linking the new account to the current account.

sahat commented 8 years ago

Thanks for reporting the issue. I suspect a JWT token is not getting sent in the Authorization header.

Is this behavior happening in production or development?

sahat commented 8 years ago

There seems be the issue: https://github.com/github/fetch#caveats

By default, fetch does not send cookies, which explains why req.cookies is empty during POST /auth/facebook or /auth/google.

Let me see if setting credentials: 'same-origin' fixes the issue.

maael commented 8 years ago

Thanks for the fix!