How to store cookie value as a variable in Ionic 3 WordPress API -
I have my ionic app talking to my WordPress. I needed to consume a particular endpoint on a particular page. The endpoint requires cookie which I have already generated using an endpoint. I have managed to store the cookie in ionic storage and can also retrieve as a string variable. The challenge i the authentication generates cookie and cookie_name. I want to get only the value of the cookie as indicated in the image below so i can use it with another endpoint in another page.
In addition I want to print error if any on a toast.
If there i any other best way to do this I had appreciate it.
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController, AlertController, Events } from 'ionic-angular';
import { HttpClient } from '@angular/common/http';
import { Storage } from '@ionic/storage';
/**
* Generated class for the LoginPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
username: string;
password: string;
cooks: any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public http: HttpClient,
public toastCtrl: ToastController,
public storage: Storage,
public alertCtrl: AlertController,
public events: Events
) {
this.username = "";
this.password = "";
}
login(){
//this will generate and uthenticate cookie
this.http.get("http://academy.soutechapps.com/api/auth/generate_auth_cookie/?insecure=cool&username=" + this.username + "&password=" + this.password)
.subscribe(data => {
console.log(data);
let response = data;
this.res = response;
console.log("this is expected cookie", this.res);
//I want to throw error on toast controller here
/* if(response.error){
this.toastCtrl.create({
message: response.error,
duration: 5000
}).present();
return;
} */
this.storage.set("userLoginInfo", response).then( (data) =>{
this.alertCtrl.create({
title: "Login Successful",
message: "You have been logged in successfully.",
buttons: [{
text: "OK",
handler: () => {
this.events.publish("updateMenu");
if(this.navParams.get("next")){
this.navCtrl.push(this.navParams.get("next"));
} else {
this.navCtrl.pop();
}
}
}]
}).present();
})
});
}
I want to use the cookie with this endpoint but in another page
/* ionViewDidLoad(){
this.http.get("http://academy.soutechapps.com/api/auth/get_currentuserinfo/?cookie=" + this.res)
.subscribe(usercookie=> {
console.log(usercookie);
//let response = data;
}
)} */
}
wordpress ionic-framework ionic3 wordpress-rest-api
add a comment |
I have my ionic app talking to my WordPress. I needed to consume a particular endpoint on a particular page. The endpoint requires cookie which I have already generated using an endpoint. I have managed to store the cookie in ionic storage and can also retrieve as a string variable. The challenge i the authentication generates cookie and cookie_name. I want to get only the value of the cookie as indicated in the image below so i can use it with another endpoint in another page.
In addition I want to print error if any on a toast.
If there i any other best way to do this I had appreciate it.
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController, AlertController, Events } from 'ionic-angular';
import { HttpClient } from '@angular/common/http';
import { Storage } from '@ionic/storage';
/**
* Generated class for the LoginPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
username: string;
password: string;
cooks: any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public http: HttpClient,
public toastCtrl: ToastController,
public storage: Storage,
public alertCtrl: AlertController,
public events: Events
) {
this.username = "";
this.password = "";
}
login(){
//this will generate and uthenticate cookie
this.http.get("http://academy.soutechapps.com/api/auth/generate_auth_cookie/?insecure=cool&username=" + this.username + "&password=" + this.password)
.subscribe(data => {
console.log(data);
let response = data;
this.res = response;
console.log("this is expected cookie", this.res);
//I want to throw error on toast controller here
/* if(response.error){
this.toastCtrl.create({
message: response.error,
duration: 5000
}).present();
return;
} */
this.storage.set("userLoginInfo", response).then( (data) =>{
this.alertCtrl.create({
title: "Login Successful",
message: "You have been logged in successfully.",
buttons: [{
text: "OK",
handler: () => {
this.events.publish("updateMenu");
if(this.navParams.get("next")){
this.navCtrl.push(this.navParams.get("next"));
} else {
this.navCtrl.pop();
}
}
}]
}).present();
})
});
}
I want to use the cookie with this endpoint but in another page
/* ionViewDidLoad(){
this.http.get("http://academy.soutechapps.com/api/auth/get_currentuserinfo/?cookie=" + this.res)
.subscribe(usercookie=> {
console.log(usercookie);
//let response = data;
}
)} */
}
wordpress ionic-framework ionic3 wordpress-rest-api
add a comment |
I have my ionic app talking to my WordPress. I needed to consume a particular endpoint on a particular page. The endpoint requires cookie which I have already generated using an endpoint. I have managed to store the cookie in ionic storage and can also retrieve as a string variable. The challenge i the authentication generates cookie and cookie_name. I want to get only the value of the cookie as indicated in the image below so i can use it with another endpoint in another page.
In addition I want to print error if any on a toast.
If there i any other best way to do this I had appreciate it.
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController, AlertController, Events } from 'ionic-angular';
import { HttpClient } from '@angular/common/http';
import { Storage } from '@ionic/storage';
/**
* Generated class for the LoginPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
username: string;
password: string;
cooks: any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public http: HttpClient,
public toastCtrl: ToastController,
public storage: Storage,
public alertCtrl: AlertController,
public events: Events
) {
this.username = "";
this.password = "";
}
login(){
//this will generate and uthenticate cookie
this.http.get("http://academy.soutechapps.com/api/auth/generate_auth_cookie/?insecure=cool&username=" + this.username + "&password=" + this.password)
.subscribe(data => {
console.log(data);
let response = data;
this.res = response;
console.log("this is expected cookie", this.res);
//I want to throw error on toast controller here
/* if(response.error){
this.toastCtrl.create({
message: response.error,
duration: 5000
}).present();
return;
} */
this.storage.set("userLoginInfo", response).then( (data) =>{
this.alertCtrl.create({
title: "Login Successful",
message: "You have been logged in successfully.",
buttons: [{
text: "OK",
handler: () => {
this.events.publish("updateMenu");
if(this.navParams.get("next")){
this.navCtrl.push(this.navParams.get("next"));
} else {
this.navCtrl.pop();
}
}
}]
}).present();
})
});
}
I want to use the cookie with this endpoint but in another page
/* ionViewDidLoad(){
this.http.get("http://academy.soutechapps.com/api/auth/get_currentuserinfo/?cookie=" + this.res)
.subscribe(usercookie=> {
console.log(usercookie);
//let response = data;
}
)} */
}
wordpress ionic-framework ionic3 wordpress-rest-api
I have my ionic app talking to my WordPress. I needed to consume a particular endpoint on a particular page. The endpoint requires cookie which I have already generated using an endpoint. I have managed to store the cookie in ionic storage and can also retrieve as a string variable. The challenge i the authentication generates cookie and cookie_name. I want to get only the value of the cookie as indicated in the image below so i can use it with another endpoint in another page.
In addition I want to print error if any on a toast.
If there i any other best way to do this I had appreciate it.
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController, AlertController, Events } from 'ionic-angular';
import { HttpClient } from '@angular/common/http';
import { Storage } from '@ionic/storage';
/**
* Generated class for the LoginPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
username: string;
password: string;
cooks: any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public http: HttpClient,
public toastCtrl: ToastController,
public storage: Storage,
public alertCtrl: AlertController,
public events: Events
) {
this.username = "";
this.password = "";
}
login(){
//this will generate and uthenticate cookie
this.http.get("http://academy.soutechapps.com/api/auth/generate_auth_cookie/?insecure=cool&username=" + this.username + "&password=" + this.password)
.subscribe(data => {
console.log(data);
let response = data;
this.res = response;
console.log("this is expected cookie", this.res);
//I want to throw error on toast controller here
/* if(response.error){
this.toastCtrl.create({
message: response.error,
duration: 5000
}).present();
return;
} */
this.storage.set("userLoginInfo", response).then( (data) =>{
this.alertCtrl.create({
title: "Login Successful",
message: "You have been logged in successfully.",
buttons: [{
text: "OK",
handler: () => {
this.events.publish("updateMenu");
if(this.navParams.get("next")){
this.navCtrl.push(this.navParams.get("next"));
} else {
this.navCtrl.pop();
}
}
}]
}).present();
})
});
}
I want to use the cookie with this endpoint but in another page
/* ionViewDidLoad(){
this.http.get("http://academy.soutechapps.com/api/auth/get_currentuserinfo/?cookie=" + this.res)
.subscribe(usercookie=> {
console.log(usercookie);
//let response = data;
}
)} */
}
wordpress ionic-framework ionic3 wordpress-rest-api
wordpress ionic-framework ionic3 wordpress-rest-api
asked Nov 19 '18 at 12:41


Vin Nwaikwu
40111
40111
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374882%2fhow-to-store-cookie-value-as-a-variable-in-ionic-3-wordpress-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374882%2fhow-to-store-cookie-value-as-a-variable-in-ionic-3-wordpress-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown