You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Node, in order to make sure we don't have an incorrect api key, it would be great if we can have an async function that checks that our sdk was initialized correctly.
Describe the solution you'd like
maybe await (new PostHog(apiKey)).validate(), or await PostHog.build(apiKey, { throwOnError: true })
Describe alternatives you've considered
I tried calling getAllFlags() and reloadFeatureFlags() but they don't throw, and I don't have flags that I can use to check.
Related sub-libraries
All of them
posthog-web
posthog-node
posthog-react-native
Additional context
Thank you for your feature request – we love each and every one!
The text was updated successfully, but these errors were encountered:
@aqeelat I think a good solution would be to create a new function that checks if apiKey is valid by making a request for PostHog server, and then calling it into constructor block, like this:
typeOOptions={throwOnError: boolean;};classO{readonlyapiKey: string;readonlythrowOnError: boolean;constructor(apiKey: string,options: OOptions){this.apiKey=apiKey;this.throwOnError=options.throwOnError;this.init();}privateasyncinit(): Promise<void>{constprofile=awaitthis.getProfile();if(profile){return;}if(!this.throwOnError){console.log('ERROR: Instance not initialized correctly');return;}thrownewError('ERROR: Instance not initialized correctly');}privateasyncgetProfile(): Promise<boolean>{returnPromise.resolve(false);}}newO('api-1234',{throwOnError: true,});
This way, it wouldn't affect the end user because they wouldn't need to call a new function, just instantiate the class normally.
I'd not call in the constructor but rather have as a method you could call yourself if needed. await posthog.validate() or something.
I think there's an API to validate the apiKey added by @zlwaterfield
Is your feature request related to a problem?
In Node, in order to make sure we don't have an incorrect api key, it would be great if we can have an async function that checks that our sdk was initialized correctly.
Describe the solution you'd like
maybe
await (new PostHog(apiKey)).validate()
, orawait PostHog.build(apiKey, { throwOnError: true })
Describe alternatives you've considered
I tried calling
getAllFlags()
andreloadFeatureFlags()
but they don't throw, and I don't have flags that I can use to check.Related sub-libraries
Additional context
Thank you for your feature request – we love each and every one!
The text was updated successfully, but these errors were encountered: