Tuesday 14 March 2017

Trying to send data to back end while logging in with facebook

Im trying to send data from the frontend to the backend to save some of the info the user entered before clicking the facebook link. I tried to a do simple test body (JSON.stringy(random stuff)) I couldn't get access to the data made with ajax.

app.get("/login/facebook", function(req, res, next){
    passport.authenticate("facebook" , function(err , user , info){
        console.log("--REq.body FACEBOOk------- : ", req.body)
    } )(req, res, next) ;
});
app.get("/login/facebook/return",
    passport.authenticate("facebook", {failureRedirect:"/login"}),
    function(req, res){
        console.log("--REq.body INSIDE RETURN> FACEBOOk------- : ", req.body)
        res.redirect("/")
    }
)

Front End:

$(".fbLink").on("click", function(){
    alert("clicked")
    $.ajax({
        method : "GET",
        url : "/login/facebook",
        data : JSON.stringify({"sent" : "from client"}),
        contentType: "application/json",
        success : function(data){
            alert("success");
        }
    })
})

The second (for route /login/facebook/return) returns an empty object The first app.get. I don't see any console

The user get saved from Facebook. just cant get the data he entered.

The alert "click" gets alerted.

I'm able to use req.body at other parts in the file. So that means that req.body is available.



via jack blank

No comments:

Post a Comment