react-oidc-context icon indicating copy to clipboard operation
react-oidc-context copied to clipboard

Dynamically changing authority

Open josephkmh opened this issue 1 year ago • 3 comments

I'm using Keycloak with multiple realms, which means I have various combinations of authority / client_id I might initialize with. These can change at run time in my react application based on how the user chooses to log in.

Currently the only way to change the authority and force a new UserManager instance to be created is by forcing recreation of the AuthProvider, for example using a key:

<AuthProvider {...oidcConfig} key={oidc.authority}>
  <RestOfTheApp />
</AuthProvider>

Unfortunately this causes the whole react tree to re-render from this point.

I see some users have had similar requests in a different issue about multiple simultaneous authorities.

Would you be open to supporting a way to dynamically update the underlying UserManager instance? If so, I'm happy to submit a PR. Otherwise our solution will probably be to roll our own context to support this, but otherwise duplicating what this library already provides. Thanks!

josephkmh avatar Sep 20 '23 09:09 josephkmh

After reading this issue, it seems like your position is that changing settings dynamically should not be supported.

josephkmh avatar Sep 20 '23 10:09 josephkmh

Thanks for the tip about the key in AuthProvider, that works like expected for me

jitbasemartin avatar Feb 13 '24 20:02 jitbasemartin

I'm interested too !

In the meantime, @jitbasemartin could you please provide more information about what you did please ?

Sanch0ous avatar Jun 24 '24 09:06 Sanch0ous