Skip to content

Commit a95e340

Browse files
committed
wip: start to generate imports, be clearer in docs of mpdule.ts
1 parent 10562b2 commit a95e340

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/module.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { defineNuxtModule, useLogger, addServerHandler, addImportsDir, createResolver, resolveModule, addTemplate } from '@nuxt/kit'
22
import defu from 'defu'
33
import { NextAuthOptions } from 'next-auth'
4-
import { parseURL } from 'ufo'
54

65
export interface NextAuthConfig {
76
/**
@@ -62,13 +61,23 @@ export default defineNuxtModule<ModuleOptions>({
6261
// 2.1. Get options
6362
const nextAuthOptions = options.nextAuth
6463

65-
// 2.2. Reduce the providers to id, name, type and options:
66-
// - `options` are what was used to instantiate the provider by the user in the `nuxt.config.ts`, we can use them for later re-instantiation in the auth-middleware
67-
// - this allows us to serialize this correctly in step 2.3., as additional non-serializable properties (that we can get back by re-instatiating) are filtered out
64+
// 2.2. Reduce the providers to id, name, type and options. This allows us to do two things:
65+
// - the `options` are what was used to instantiate the provider by the user in the `nuxt.config.ts`, we can use them for later re-instantiation in the auth-middleware
66+
// - serialize the whole config correctly in step 2.3., as additional non-serializable properties (that we can get back by re-instatiating) are filtered out
6867
const providerOptions = nextAuthOptions.options.providers.map(({ id, name, type, options }) => ({ id, name, type, options }))
6968

7069
// 2.3. Create virtual imports
7170
// - TODO: add imports for all providers
71+
const providerImports = providerOptions.map(({ id }) => `import ${id} from next-auth/providers/${id}`)
72+
const preamble = `
73+
${providerImports.concat('\n')}
74+
75+
const providers = ${JSON.stringify(providerOptions.map(({ id }) => id))}
76+
`
77+
console.log('hiiii', preamble)
78+
nuxt.options.nitro.virtual = defu(nuxt.options.nitro.virtual, {
79+
'#sidebase/providers': preamble
80+
})
7281
nuxt.options.nitro.virtual = defu(nuxt.options.nitro.virtual,
7382
{
7483
'#sidebase/auth': `export default ${JSON.stringify({

0 commit comments

Comments
 (0)