goal
I am using Keycloak in an Angular2 project as an authentication service. For this I use a javascript adapter.
Problem
I initialize the Keycloak object in main.ts. Login is not required directly. During implementation, I encountered a problem. When the page is refreshed, a new Keycloak object is created that does not preserve the original status (loginstatus, token, etc.). I tried to save the Keycloak object in localStorage. When I get (after JSON builds and parses) an object, the object is not recognized as a Keycloak object.
Current workaround
When logging in, I store the boolean value "authenticated" in localStorage. I check in main.ts if this “authenticated” value is true. Then register (after initialization) when the page is refreshed. This leads to a two-page update, because the user is redirected to Keycloak and directly
Question
Is there a way to save a Keycloak object? Or can you check if the user was already registered when creating a new object?
source share