

I commented some validation and saving middleware here just for convenient, you need to do it if you wanna use it in production. 1Ĭonst asyncAllFBAuth = ( req, res, next) => ,ģ.5 Finally, send the JWT back to the client. We need to exchange for the long time token and we need to retrieve the user information via the short time token. We need to implement the startToAuth() 1ģ.3 Add the middleware you need to Promise.all the 2 sub-steps you need for Step 3 Now let’s assume the user grants our permission. So, how do you get the access token? It will trigger the checkLoginState() that you just set and pass the token as the parameter. It seems no matter what you set in that Valid OAuth redirect URIs in Developer portal, if you use official SDK, it won’t go there. })( document, "script", "facebook-jssdk") The user decline our request, do something here if you want. The if else inside FB.getLoginStatus is where add your own logic.
Javascript for faceboof button code#
Now add the code for that login button, 2 things to notice, 3.1 Add facebook button 1Īdd Zepto and your own javascript file. You can still get the access token in the client side js.ģ. Which means you could use Promise.all to make it happen faster.Ī trick in step.2 is facebook won’t redirect you to the callback URL as it did when you use passport.js, but don’t worry here. The sub-steps in Step 3 could happen at the same time. Because when your jwt expires, you could simply let the user login via facebook again.

If you just use facebook to authenticate a user, you could skip step 4 entirely. The client could use the token to access an authorized endpoint. Generate a JSON web token(jwt) with your own signature and passback it back to the client.

