nowaythatworked / auth-astro

Community maintained Astro integration of @auth/core
280 stars 42 forks source link

Initialize auth config lazily #60

Open shishkin opened 7 months ago

shishkin commented 7 months ago

I ran into an issue when Astro SSR node build tried to eagerly initialize Auth.js config and required a working connection to the adapter DB (Mongo in my case). Unfortunately Auth.js config doesn't allow passing a factory function instead of an adapter instance.

I wonder if auth-astro could instead use a factory of Auth.js config in its build phase to avoid eagerly evaluating adapters.

As a workaround, I manager to use Proxy to wrap and lazy initialize the MongoDBAdapter. But that feels like a horrible hack.

I think issues like https://github.com/nowaythatworked/auth-astro/issues/52 might be resolved by that change as well.

danielnaab commented 1 month ago

Is this lazy initialization from Auth.js compatible with auth-astro? https://authjs.dev/reference/nextjs#lazy-initialization