Allow the @auth/sveltekit framework to use platform variables for config data #6743
Labels
accepted
The feature request is considered. If nobody works actively on it, feel free to.
enhancement
New feature or request
Description 📓
The current @auth/sveltekit framework assumes that config variables will be available outside of the scope of the hooks handler. Note that in the code below, the SvelteKitAuth function is returning a handler function that is generated anonymously in the framework.
Some platforms, notably cloudflare for my case, provide environment variables via the platform properties which are only available in the hooks handler via the event parameter. Note that the sveltekit hooks Handler has a signature of:
Here is a link to the cloudflare sveltekit docs for environment variables as a reference.
Typically to get to platform variables a developer will use
event.platform.env.VARIABLE_NAME
.Because of the method of generating the config data outside of the hooks handler, the event object isn't available. I would like to add an optional dynamicOptions parameter that is a function that will generate a config and can have access to the event object. See proposed changes in the linked PR.
How to reproduce ☕️
Unfortunately this is a complicated feature to test because there is a bug with running
pnpm run build
in the apps/dev/sveltekit directory. It causes vite build to fail to resolve the 'crypto' module. See issuepnpm run build
is required to test with the cloudflare local development platform "wrangler". I have 'hacked' the node_modules/@auth/sveltekit module outside of the next_auth development environment and confirmed that the changes do provide access to the platform variables locally on wrangler and also when deployed to cloudflare production. I have tried a couple of ways to get a publishable test working that looks verifiable.pnpm run build
and then do regular publish commands. The workspace declarations in package.json aren't getting converted.Perhaps a core contributor could publish a feature branch so that I could normally import @auth/sveltekit from the feature branch? I could then publish an app to a public GitHub repo that should work just fine. Note that getting the sveltekit demo working on cloudflare is also dependent on #6741 . I opened that issue and I could consolidate these two if necessary for a feature branch to make testing easier.
Contributing 🙌🏽
Yes, I am willing to help implement this feature in a PR
The text was updated successfully, but these errors were encountered: