Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Api Keys #871

Open
guilleCM opened this issue Oct 30, 2024 · 4 comments
Open

Dynamic Api Keys #871

guilleCM opened this issue Oct 30, 2024 · 4 comments
Labels
type: question Request for information or clarification. Not an issue.

Comments

@guilleCM
Copy link

Hello,

I'm using an app with multiple domains, and I would like to switch between different apiKeys depending on which domain is being used to access the app. However, once I instantiate the component with a particular apiKey, if I then access the app via another domain, I encounter the following error: "Error: Loader must not be called again with different options."

I've tried instantiating it in different components and even in separate routes within the same application to ensure different Loaders are created, but I still encounter the same error.

My question is: once a Loader is instantiated with an apiKey, is it possible to dynamically change it? Or is there any recommended approach to handle multiple apiKeys?

Thank you in advance for your help!

@guilleCM guilleCM added triage me I really want to be triaged. type: question Request for information or clarification. Not an issue. labels Oct 30, 2024
@usefulthink
Copy link
Contributor

In short, you can't have multiple API keys in the same global scope.

The API key will become part of the URL for the script that loads the Maps JavaScript API. Once that is loaded, it is no longer possible to "unload" it (for example, to replace the API key with something else). This is why the loader will report an error if you try to create a new instance with a different API key.

@usefulthink usefulthink removed the triage me I really want to be triaged. label Oct 30, 2024
@guilleCM
Copy link
Author

Thank you for your reply! So I understand that it is a limitation of the Google Maps JavaScript API and not of this library itself.

@usefulthink
Copy link
Contributor

Pretty much that, yes.

@HaNdTriX
Copy link

HaNdTriX commented Dec 3, 2024

@guilleCM I just created an experimental Google Maps API loader, that isolates the entire SDK via iframe. This allows us to reinstantiate the entire SDK or have multiple different Google Maps SDKs in the same page context.

The API of the experimental loader is almost the same except that it supports the AbortController pattern and multiple instances of the SDK.

Check out #210 (comment) for more infos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants