CheckSession for Angular

I have multi app setup on same domain but different subdomains with single sign on.
I usually use loginWithRedirect when my pages require login or I simply do not use login (only signup pages).
Now I have a page in which you must or you do not must be logged in depending on “public” parameter from API and one app redirects to this new app to view that page.

I though “getAccessTokenSilently” would handle this case, but from it i get login Required error despite being logged in on my other subdomain. So at the moment I am handling it if it is not “public” I get 401 from API, call loginWithRedirect and reload page again. And if user visits public site he is not aware he is logged in.

Not the fan of this approach, I read there was “CheckSession” but with old auth0-spa.js So I am checking is there any alternative. The ideal flow would be very similar to loginWithRedirect, it would just skip the login screen.

!IsAuthenticated->someNewTryLoginWithRedirect->userOnIdentityProvider->proceed as loginWithRedirect.

!IsAuthenticated->someNewTryLoginWithRedirect->userNotOnIdentityProvider->return NotAuthenticated and that is it I can handle both cases perfectly without unnecessary failed api calls, reloading of the page and so on.

Any ideas?

Hi @filip.vuletic

Welcome back to the Auth0 Community!

Unfortunately, Angular does not offer a similar function as the checkSession(). Even in the case of checkSession(), you would receive Failed Silent Auth errors since the function is intended to be executed when checking for an active session.

The only functions available inside Angular, as you have mentioned, would be to check the authentication state via isAuthenticated() and isLoading() and handling these errors accordingly whenever the user is not logged in and prevent unnecessary redirections if they do not have an active session. You can read more about them in the Github documentation of the SDK.

If necessary, I would recommend you to open an issue on the SDK’s Github page regarding your implementation and look for other solution’s workaround.

If you have any other questions, feel free to leave a reply!

Kind Regards,
Nik

1 Like