feat: add initAuthKit() for runtime config from secrets managers#449
Open
ShooTeX wants to merge 1 commit into
Open
feat: add initAuthKit() for runtime config from secrets managers#449ShooTeX wants to merge 1 commit into
ShooTeX wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #448
Summary
initAuthKit(config: AuthKitConfig)exported from the package, letting users supply secrets from a vault or secrets manager instead of (or alongside) environment variablesenv-variables.tsmodule with a reactiveconfigproxy — values set viainitAuthKittake precedence; missing keys fall back to the correspondingprocess.envvariable, so existing deployments need no changesinitAuthKitcalls are merged, allowing partial/grouped overridesAuthKitConfiginterface is also exported for typingUsage
Caveats
Overrides are stored in a module-level singleton (
globalThis[Symbol.for('workos.authkit.overrides')]), which meansinitAuthKitmust be called once per runtime instance. In practice this is fine for long-lived Node.js servers, but worth noting for:initAuthKitmust run during the cold-start initialisation path (e.g. outside the handler, or in a top-levelawaitbefore the handler is invoked).A future improvement could expose a request-scoped or lazy-init variant to address these cases more ergonomically.
Test plan
config.tscovering env fallbacks,initAuthKitoverrides, merging, and clearing back to env valuesinitAuthKitinstead ofObject.definePropertyhacks on the old env-variables module