IOnic serve case:
when i run ionic serve http call return null in response header. i need headers to send in every next call for secure authentication. but Api returning null in response header when i call login http call.
Ionic run android case:
But another case is when i run ionic run android it give me response header in login call but right after the login call when i call next http call it returns null in response header of next call.
Here is my Login code:
Login(email, password) {
let body = JSON.stringify({email: email, password: password});
//HTTP POST CALL FOR LOGIN
return this.http.post(this.LOGIN_URL, body, {headers: this.contentHeader}).subscribe(response => {
if (response) {
console.log('in login if');
console.log(response.headers.get('uid'));
console.log(response.headers.get('client'));
console.log(response.headers.get('access-token'));
this.uid = response.headers.get('uid');
this.client = response.headers.get('client');
this.access_token = response.headers.get('access-token');
//saving header for next call
Save_Header(this.access_token, this.client, this.uid );
} else{
// login failed
console.log("coming in........");
this.error = 'Something went wrong';
// this.loading = false;
}
}
Here is function which saving headers for next call:
Save_Header(access_token,client, uid){
this.contentHeader.append('access-token', access_token);
this.contentHeader.append('client', client);
this.contentHeader.append('uid', uid);
//console.log(this.contentHeader);
}
function for getting header for next call:
Get_Header(){
return this.contentHeader;
}
Next http call:
Get_All_Delivered_orders(){
console.log("in userservice all delivered orders")
console.log(this.Get_Header());
return this.http.get(URL,{headers: this.Get_Header()});// getting saved headers
}