bjerkio/oidc-react

Async User Manager settings

OzgeYurtsever opened this issue · 2 comments

Thank you all for providing such a great library.

In one of our workflows, we read some of the settings from a config file asynchronously instead of having environment variables. We get the below error:

'Uncaught (in promise) Error: No authority or metadataUrl configured on settings'

We want to support both environment variables and config files for settings in our distribution.

Is there a way to initialize the usermanager after the settings are resolved?

Hi there. Not the maintainer, but I wanted to share what I do in a particular project for this (though I don't have the code right in front of me). Basically, I created a small wrapper called something like <MaybeAuthProvider> where if it has the information required, it will initialize the AuthProvider with the parameters we have to wrap any children given. If we don't have the parameters, it basically returns children not wrapped. We do this because sometimes it could be a bit until we resolve the parameters, but also because we use SSR and the user won't have always created credentials at that point.

AuthProvider lets you specify the settings for the UserManager or send in your own custom one. So that can be created how you see fit at that point.

Hope it helps a little bit!

@OzgeYurtsever I'd love to get some feedback on how you expect this to work best. Maybe even a pull request ❤️

Like @pseudoramble mentioned, you can set your own UserManager. The way this works is like so:

import React from 'react';
import { UserManager, AuthProvider } from 'oidc-react';

const userManager = new UserManager({
 // ... set your config here
});

export const HelloComponent: React.FC = () => (
	<AuthProvider userManager={userManager}>
	{/* ... */}
	</AuthProvider>
);

I'm closing this now, let me know if you need anything else! Feel free to open a new issue or pull request. Thanks again!