How can I store cookie value as a variable in Ionic 3 WordPress API


#1

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;
  }
  )} */
}


#2

Does WordPress provide the same resource with JWT authentication? I really don’t know if you can or if it’s a practice to authenticate via cookies on mobile.