@Geelario wrote:
Good day Expert. Please I have a little worry if someone can help me out. I am using WordPress JWT plugins to authenticate users in my ionic 4 apps, but the issue am having is that when a user try to log in the first time it returns null, with this error message –
https://example.com/wp-json/wc/v3/customers/null?consumer_key=ck_xxxxxxxxxxxxxx&consumer_secret=cs_xxxxxxxxxxxxx.
–HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: “OK”, url: “https://example.com/wp-json/wc/v3/cu…ecret=cs_xxxxxxxxxxx”, ok: false, …}, but the local storage returns the customer data and id with a toast showing login successful. when the user tries it the second time, that’s when the user will be authenticated. But I want user to be authenticated once the login is successfulDon’t know what I have done wrong. This is my code.
login.page.ts
loginForm(){ this.platform.ready().then(() => { if((this.password != '') && (this.CFS.validateEmail(this.email))) { console.log('Email: ',this.email); console.log('Password: ',this.password); this.auth.loginCustomer(this.email,this.password).then((response) => { if(response['token']){ console.log('Returned Token: ',response['token']); console.log('Returned user enamil: ',response['user_email']); this.CFS.presentToast('Login successful', 'buttom',2000, 'success'); this.auth.getUserData(this.email).subscribe((userData) => { this.customerData = userData; console.log('Customer Data: ', this.customerData); let currentUserId = this.customerData[0].id; localStorage.setItem('currentUserId', currentUserId); let found = localStorage.getItem('currentUserId'); console.log('local storage id', found); }); this.route.navigateByUrl('/home'); } else { this.CFS.presentToast('Invalid username or password', 'buttom',2000,'danger'); } }); } else { this.CFS.presentToast('Please fill the form correctly', 'buttom',2000,'danger') } }); }
Home.page.ts
customerId:any; customerData: any = { avatar_url: 'not found', } constructor(private CFS: CommonfunctionService, private activatedRoute: ActivatedRoute, private auth: AuthService, private WC: WoocommerceService, private modalPop: ModalController) { } ngOnInit() { let isUserLoggedIn = localStorage.getItem('currentUserId'); this.WC.getUserInfo(isUserLoggedIn).subscribe((data)=>{ this.customerData = data; console.log('user data', this.customerData); }); this.WC.getWalletBalance(isUserLoggedIn).subscribe((data) =>{ this.mybalance = data; console.log('All Orders balance by a customer', this.mybalance); }); }
please I need your assistance. Thanks
Posts: 1
Participants: 1