auth0-angular
auth0-angular copied to clipboard
dynamic config auth0 module at later point after APP_INITIALIZER
Describe the problem you'd like to have solved
According the description here, Auth0 module could only be configured during APP_INITIALIZER. In my scenario, it can not work. I need to show a page(which will be translated to different languages) to the user which datacenter(each datacenter has its own set of auth0 configuration) to connect to, and only after the selection is done, I can know which auth0 configuration I should give to auth0 module.
Describe the ideal solution
Maybe allow later time configuration will help
Thanks for reaching out.
What you are describing seems to be doable with APP_INITIALIZER, but will come down to a couple of extra things:
- Store the selected datacenter in local storage
- Refresh the page after selecting a data-center
- Use the datacenter from localstorage in your APP_INITIALIZER
Even tho I can understand this might not be ideal, I believe it should work fine for your use case.
thanks for the quick response, actually I am building an Ionic Mobile App, I do not think refresh is acceptable. And as I said, the datacenter selection page needs to be translated to different languages which means when the page is shown, the APP_INITIALIZER should be already done, right? I am checking auth0-spa-js this package, maybe I need to build an AuthService myself?
We currently have no way for you to initialize our SDK at a later point in time. You can definitely leverage Auth0-SPA-JS if our Angular SDK doesn't work for you.
Could you elaborate on what settings are different between the several datacenters that would require you to initialize it at a later point in time?
We have this concept called datacenter, each datacenter has its own Auth0 domain id and client id. The first step of our App is to let the user choose which datacenter to connect to, and only after the datacenter is selected, I can know the domain id and client id and at this point I can initialize the Auth0 SDK.
And I tried to call AuthModule.forRoot in feature module which I think is wired, and yes, it did not work, lol.
And I have encounter one question when I was using Auth0-SPA-JS, does refresh token only work when I explicitly call getTokenSillently? Like I set refresh token to 7 days, id token to 20 minutes, and I close my app for 1 day, and then reopen the app, what should I expect when I call auth0Client.isAuthenticated() ?
There should be no need to call getTokenSilently
, as long as you use
const auth0 = await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
client_id: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
});
The above code will immediately call checkSession (which calls getTokenSilently under-the-hood for you).
cool, thanks for your help, but I think it is better for auth0-angular to be able to dynamically initialize
I am closing this for now, as I believe there is little demand for this and there are workaround available.
We can always reconsider this if demand increases.