Hi, So just finished developing an app which was previously using angular http for requests. I have opted for capacitor http and works really well on the browser. When i use a simulator or install app on my device it seems to not pass the data. Not sure why because on the browser everything works like it should.
Ionic:
Ionic CLI : 7.1.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 7.0.14
@angular-devkit/build-angular : 16.1.0
@angular-devkit/schematics : 16.1.0
@angular/cli : 16.1.0
@ionic/angular-toolkit : 9.0.0
Capacitor:
Capacitor CLI : 5.0.5
@capacitor/android : 5.0.5
@capacitor/core : 5.0.5
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 1.7.2
System:
NodeJS : v18.16.0 (/usr/local/Cellar/node@18/18.16.0/bin/node)
npm : 9.5.1
OS : macOS Unknown
Here is my code for the login page:
async login(){
const {email, password } = this
let body = {
"email": email.trim(),
"password": password.trim()
};
const options = {
url: 'https://usersauth.example.com/Auth/login',
data: body,
};
const response: HttpResponse = await CapacitorHttp.post(options);
if(response['status'] == 400){
var data = response['data'];
var output='';
var errorhead = "Ooops";
for(var key in data) {
output+= data[key] + '<br>';
}
this.showAlert(errorhead,output);
}
if(response['status'] == 200){
this.credentials = {
email: email.trim(),
password: password.trim()
};
this.loginFirebase(this.credentials);
this.setSessionObject(response['data']);
this.router.navigate(['tabs']);
}
}
Then on the Server side I’m using this function
public function login()
{
header( 'Access-Control-Allow-Origin: *' );
if ( $_SERVER[ 'REQUEST_METHOD' ] == "OPTIONS" )
{
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS' );
header( 'Access-Control-Allow-Headers: ACCEPT, ORIGIN, X-REQUESTED-WITH, CONTENT-TYPE, AUTHORIZATION' );
header( 'Access-Control-Max-Age: 86400' );
header( 'Content-Length: 0' );
header( 'Content-Type: application/json; charset=utf-8' );
die ;
}
$rules = [
'email' => 'required|min_length[6]|max_length[50]|valid_email',
'password' => 'required|min_length[8]|max_length[255]|validateUser[email, password]',
];
$errors = [
'password' => [
'validateUser' => 'Invalid login credentials provided'
],
'cpassword' => [
'matches' => 'Password does not match'
]
];
$input = $this->getRequestInput($this->request);
if (!$this->validateRequest($input, $rules, $errors)) {
return $this
->getResponse(
$this->validator->getErrors(),
ResponseInterface::HTTP_BAD_REQUEST
);
}
$model = new UserModel();
$user = $model->findUserByEmailAddress($input['email']);
if($user['status'] == 'Pending'){
return $this
->getResponse(
[
'error' => 'Your email is not verified',
],
ResponseInterface::HTTP_BAD_REQUEST
);
}
return $this->getJWTForUser($input['email']);
}
So what happens is that its returns validation errors say i have not inputed anything even if i did. This is only happening on device and simulator on browsers it works as it should. Any help on what am missing thanks