I am working on Ionic Project and have a two functions login()
and fetchUser(). Where fetchUser()
get data from SQlite database and return a promise.
fetchUser(storage){
return new Promise(function(resolve, reject){
storage.get('user')
.then((user) => {
if(user != null){
resolve(user);
}
})
.catch(err => reject(err));
})
}
And login funciton is like this.
login(){
this.fetchUser(this._storage)
.then(user => {return user;})
.catch(err => console.log(err));
// I want user data here
}
Everything is working fine, data is fetching successfully.
Now the problem is I want to return user (data) to login()
function. If I call login()
it returns undefined
. I think this is because I an returning value from then function.
But If I log user in console in then()
function then it is logging successfully. however it is not returning to the login function.