0

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?

Bitly
  • 728
  • 2
  • 11
  • 22
  • Does this answer your question? [Cannot get Username / given\_name when using angular-oauth2-oidc and Identity Server 4](https://stackoverflow.com/questions/51671800/cannot-get-username-given-name-when-using-angular-oauth2-oidc-and-identity-ser) – Asaf Sep 28 '20 at 07:19
  • this did not help my case. That is to get user profile info and that is the next step to this step. – Bitly Sep 28 '20 at 07:30
  • although I can see I am able to get data in session storage directly as data_obj – Bitly Sep 28 '20 at 07:30
  • how can I access that here? – Bitly Sep 28 '20 at 07:30
  • Please, share the implementation of `oauthService.getIdentityClaims()` and show how you bind the result to the template. – Francesco Colamonici Sep 28 '20 at 07:49
  • Share the code for `getIdentityClaims` method. Most probably it's an `http` call, then subscribe to that function to get the result. – uiTeam324 Sep 28 '20 at 08:17
  • To add to uiTeam324s comment: This is most likely a problem with synchronous/asynchronous functions. `let res = ...` will result in `null` because the function does not return a result right away, but when it's done (asynchronous), thus the need for `subscribe`. – Gunnar B. Sep 28 '20 at 08:23

0 Answers0