Ionic 2 code working on web but not on device


#1

I’m working on login/signin. It is working on web but on android device its showing 403 error.


#2

What’s the code you’ve used to create the login, where are you loging in to and what exact error are you receiving on your device?


#3

//login.component.ts

Loginresponse : any;
  UserLogin(){
    let data = {
      emailId: this.email,
      password: this.password
    }

    alert(data);
    this._authServ.verifyUser(data)
    .subscribe(
    (res) => {
      this.Loginresponse = res;
      this.verifySuccessfully(res);
      this.NavLogin();
    },
    (err) => {
      console.log(err);
      alert(err);
    })
  }

//login.service.ts

public verifyUser(body){
        this.getHeader();
       return this.http.post(this.baseUrl+'/signin',body,this.options)
            .map(this.extractData)
            .catch(this.handleError)
    }

  private extractData(res: Response) {
		if (res.status === 204) { return res; }
		let body = res.json();
        console.log('data',body);
		return body || { };
	}

	private handleError(error: Response | any) {
    let errMsg: string;
    if (error instanceof Response) {
      errMsg = `${error.status} - ${error.ok || ''}`;
      if (error.status === 0) {
        errMsg = `${error.status} - "No Internet"`;
      }
    } else {
      errMsg = error.message ? error.message : error.toString();
    }
    return Observable.throw(errMsg);
  }

and the error i’m reciving on device is “403-”.Preformatted text


#4

Could you please format the code of your post by using < /> , it will make your post easier to read. Thanks. Okay so 403 means forbidden. You’re trying to access something which you don’t have the appropriate rights for. Did you already inspect the payload you’re sending to your server on your browser as well as on the device?


#5

Yes i checked on both browser and device. Its working fine on browser but on device i’m getting “403-”.


#6

I asked to check if you could make sure the payload is exactly the same. I understand it’s working in the browser, but if you want to figure out why it isn’t working on the device, I would start by inspecting the payload you’re trying to send to the server on the device.


#7

Smells like a CORS issue to me.