So basically I'm requesting a post request to the server which in return, send a token in JSON object in this form:
{
token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIyLCJpc3MiOiJodHRwczovL2hvYnVkZGllcy5jb20vYXBpL2F1dGgvbG9naW5fYXBpIiwiaWF0IjoxNTE3MzkwNTkwLCJleHAiOjE1MTczOTQxOTAsIm5iZiI6MTUxNzM5MDU5MCwianRpIjoiWUxtdXJ5TkV2UzlwSEExTyJ9.nWV7OWLYdMJmZCHNP9tFuAmZ84DwzYO00O3jQ_RfhXQ"
}
What I required is to append that token with the apiUrl to get the appropriate information of a user currently logged in. The server is returning this JSON object in a variable "result" as shown below:
// for login the user in the app.
loginUser() {
//values from the login form
var data = {
email: this.emailVar,
password: this.passwordVar
}
//calling the loginUser method from the Provider: Test.ts
this.restProvider.loginUser(data)
.then((result) => {
//storing the returned Token from the server.
var login_token = result;
//storing the retured Token into Ionic Storage.
this.storage.set("tokenn", result);
console.log(result);
console.log('success');
//if successful, then set the rootPage to TabsPage
this.navCtrl.setRoot(TabsPage);
}, (err) => {
console.log(err);
});
But when I'm appending the result, stored in the storage, It's appending that retured object, wehere I only need the string.
I only required this:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIyLCJpc3MiOiJodHRwczovL2hvYnVkZGllcy5jb20vYXBpL2F1dGgvbG9naW5fYXBpIiwiaWF0IjoxNTE3MzkwNTkwLCJleHAiOjE1MTczOTQxOTAsIm5iZiI6MTUxNzM5MDU5MCwianRpIjoiWUxtdXJ5TkV2UzlwSEExTyJ9.nWV7OWLYdMJmZCHNP9tFuAmZ84DwzYO00O3jQ_RfhXQ"
So, how to extract that string from the object in my Ionic app.