Data not displayed unless manual page refresh Angular 8

233 views Asked by At

I have implemented Okta authentication and I am getting some userdata from Okta once the user successfully logs in. I am making call in ngOninIt() on landing page to get user data. It says no data found but when I manually refresh the page it console.logs the entire data. I tried writing logic to refresh the page automatically but still not working.

 ngOnInit() {
    let res = this.oauthService.getIdentityClaims();
      if (res === null) {
        console.log('no data received');
        return null;              // I also tried window.location.refresh() and location.refresh();
      } else {
        console.log(res);
        return res;
      }

this is how I refreshed the page:

ngOninIt{
if (!localStorage.getItem('foo')) { 
     localStorage.setItem('foo', 'no reload') 
     location.reload() 
     } else {
            localStorage.removeItem('foo') 
            }
}

Even after reloading the page this way, I do not receive any data but when I manually do it, I get a response. Can you suggest how to get response as soon as I land on the landing page?

0

There are 0 answers