sample-angular-oauth2-oidc-with-auth-guards
sample-angular-oauth2-oidc-with-auth-guards copied to clipboard
Add observable to indicate if User Profile was loaded
In the main service of this sample we load the User Profile like this:
https://github.com/jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards/blob/4ee8e2862bb9b825015a9bd5213d07984c9cea13/src/app/core/auth.service.ts#L73-L75
I suspect some people will want to "wait" for the profile to be loaded before doing stuff. So it might make sense to add isUserProfileLoaded$ observable similar to isAuthenticated$ and isDoneLoading$.
However this is solved, this would be very useful for us. We have several components that rely on information coming from the response to loadUserProfile. As it stands, we're dealing with a race condition where a component is loaded before the user profile request completes. We can probably add something akin to your APP_INITIALIZER process. However (and this is untested and could be completely incorrect), I believe that if a user were to logout and log back in (not refreshing/reinitializing the app), then the user profile data would need to be re-requested and I'd be back in the same situation.
Anyway, I'm interested in a solution here and happy to provide more details of our situation to help develop one.
Thanks for the feedback! That sounds like a typical use case indeed.
Don't think too much of the proposed feature by the way, it would probably be a very straightforward boolean observable similar to isAuthenticated$.
I'm not sure if I'll get to introducing this all too soon though, as my open source focus is currently mostly elsewhere.
If anyone ends up doing an implementation feel free to let us know what approach you took!