My problem concerns the user of Passport with Express API and returning a cookie back to Ember.
I have sent the Username and password to the Express server and Serialized this to get an ID. I can see the identification using:
console.log('Serializing User: ', req.session.passport.user)
OUTPUT: Serializing User: 59957ccd9da3da8d1dce2a72
I can get access to this identification but I am struggling to send it back to Ember as a cookie.
So far I have:
Express
app.post('/api/authenticate',
passport.authenticate('local'),
function(req, res){
console.log('User ID: ', req.session.passport.user)
//Write the cookie
res.cookie('CookieName', req.session.passport.user)
//Get the cookie as a cookie and stringify
var cookie = JSON.stringify(res.req.headers.cookie)
res.send({'name': 'CookieName', 'value': cookie})
})
Ember
authenticate(username, password){
console.log(username);
console.log(password);
console.log(apiHost)
//Send a promise to express with username and password to be resolved
///get express to search database
var promise = this.get('ajax').request(apiHost, {
method: 'POST',
data: {
username: username,
password: password
}
})
//accept data as a cookie
return promise.then((result) => {
//debugging
var obj = result;
console.log(obj);
var message
if(result.error){
console.log("error exists - let's reject")
message = promise["error"];
return Promise.reject(message);
} else {
console.log("promise accepted")
message = promise;
return Promise.resolve(message);
}
})
}
Postman Pretty states: Unexpected 'B' Postman Raw states: Bad Request
This is my first time using Passport, Cookies and putting in place Authentication.
I just need to accept the JSON and have it become a cookie so that I can request access to the session in Express in the future
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire