Hello everyone, for last few days i tried to figure out how to make application with login system, (need log in to use app properly ). My target is to login to wordpress site using wp restapi.
The biggest problem i wasn’t able to find anything working for current app ( btw finding anything that works for latest ionic is a nightmare )
My Question is: How and whats best practice to login to page and safely hold information’s about session?
What exactly i need ( i think ) is:
- Create form - got it
- Create event on form submit - got it
- Send the username and password to my wp restapi controller
- (after successful login ) Hold information about logged account in session
- Normally use app with, i will need to make many requests do get data from server so i thought about making some module which will control and send requests ( safely with authentication ).
*EDIT
heres WP REST Api Authentication
But i can’t find anything to work!
Here’s my code as I’m writing this topic.
import { Component } from '@angular/core';
import { Validators, FormBuilder, FormGroup } from '@angular/forms';
import { Http, Headers } from '@angular/http';
@Component({
selector: 'page-login',
templateUrl: 'login.html'
})
export class LoginPage {
private loginData: FormGroup;
constructor( private formBuilder: FormBuilder, private http: Http) {
this.loginData = this.formBuilder.group({
username: ['', Validators.required],
password: ['', Validators.required],
});
}
login(){
let headers = new Headers();
headers.append('Content-Type', 'json');
console.log(headers);
let data = {
action: "login",
username: this.loginData.value.username,
password: this.loginData.value.password
};
console.log(data);
this.http.post('http://demo.wp-api.org/wp-json/wp/v2/posts', JSON.stringify(data), { headers: headers })
.subscribe(res => {
console.log(res.json());
}, (err) => {
console.log(err);
});
}
}
There is few things that i completely or particularly don’t understand:
- I tried to use Angular $http, but this.http() is said not to be a function, meanwhile on Angular documentation this should work as a normal function
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
}, function errorCallback(response) {
});
-
Ionic authentication.
Ionic Auth has been deprecated. As of January 31, 2018, we will no longer provide the Ionic Auth user authentication service.
Its not gonna be supported after January 31 2018 but should i still use it? Anyway i tried because i didn’t find any other way to authenticate but i gotCannot find '@ionic/cloud-angular'
. -
Why there is such a mess about information’s about Ionic ummmk 2/3? I see im using version 3.6.0 but documentation is for v1 and v2. Srsly this is one big mess for me!