When creating users, I am trying to retrieve the ID of the newly created user. However, I am facing difficulty getting it through the callback function. Here is what my current setup looks like:
controller.js:
Auth.createUser({
name: this.user.name,
email: this.user.email,
password: this.user.password,
}, function (err, user) {
console.log(user); // Only returns 'name', 'email', 'password', not the '_id'
}
auth.service.js:
/**
* Create a new user
*
* @param {Object} user - user info
* @param {Function} callback - function(error, user)
* @return {Promise}
*/
createUser(user, callback) {
return User.save(user, function(data) {
$cookies.put('token', data.token);
currentUser = User.get();
return safeCb(callback)(null, user);
}, function(err) {
Auth.logout();
return safeCb(callback)(err);
})
.$promise;
},
EDIT: If I try using the API endpoint:
$http.post('/api/users/', {
name: this.usr.name,
email: this.usr.email,
password: this.usr.password
})
The returned object is:
Object { data: Object, status: 200, headers: headersGetter/<(), config: Object, statusText: "OK" }
Within the 'data' property, there is:
data {
token: eyJhbGciOiJ...Vs3Ng14ycQA
__proto__: Object
}
As a result, I am unable to retrieve the user information. Any assistance on how to overcome this issue would be greatly appreciated. Thank you in advance.