Skip to content

Commit

Permalink
feat(nuxt): add import for 'auth' in serverDir
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Jan 23, 2024
1 parent 932d95c commit 725c026
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/nuxt/src/runtime/core/setupModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ async function initModules(nuxt: Nuxt, resolver: Resolver) {
projectName,
rootModuleDir: join(nuxt._pergel.rootDir, `${moduleName}-${projectName}`),
serverDir: join(nuxt._pergel.serverDir, `${moduleName}-${projectName}`),
projectNamePascalCase: camelCase(`pergel${firstLetterUppercase(projectName)}`, { normalize: true }),
projectNameCamelCase: camelCase(`${firstLetterUppercase(projectName)}`, { normalize: true }),
projectNameCamelCaseWithPergel: camelCase(`pergel${firstLetterUppercase(projectName)}`, { normalize: true }),
},
rootOptions: module,
})
Expand Down Expand Up @@ -273,7 +274,8 @@ export async function setupModules(data: {
projectName,
rootModuleDir: join(data.nuxt._pergel.rootDir, `${moduleName}-${projectName}`),
serverDir: join(data.nuxt._pergel.serverDir, `${moduleName}-${projectName}`),
projectNamePascalCase: camelCase(`pergel${firstLetterUppercase(projectName)}`),
projectNameCamelCase: camelCase(`${firstLetterUppercase(projectName)}`),
projectNameCamelCaseWithPergel: camelCase(`pergel${firstLetterUppercase(projectName)}`),
},
rootOptions: module,
})
Expand Down
8 changes: 7 additions & 1 deletion packages/nuxt/src/runtime/core/types/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ export interface ResolvedPergelModuleOptions {
* test -> Test
*/

/**
* @default
* TestHello -> testHello
*/
projectNameCamelCase: string

/**
* @default
* testHello -> pergelTestHello
*/
projectNamePascalCase: string
projectNameCamelCaseWithPergel: string

/**
* @default
Expand Down
15 changes: 12 additions & 3 deletions packages/nuxt/src/runtime/modules/lucia/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export default definePergelModule<LuciaModuleOptions, ResolvedLuciaModuleOptions
/* ts */`
import { session, user } from '#${options.projectName}/drizzle/schema'
const connect = await ${options.projectNamePascalCase}().drizzle().postgresjs().connect({})
const connect = await ${options.projectNameCamelCaseWithPergel}().drizzle().postgresjs().connect({})
export const auth = ${options.projectNamePascalCase}().lucia().use({
export const auth = ${options.projectNameCamelCaseWithPergel}().lucia().use({
db: connect,
options: { },
session,
Expand All @@ -102,7 +102,7 @@ export const auth = ${options.projectNamePascalCase}().lucia().use({
/* ts */`
import { auth } from '#${options.projectName}/lucia'
export default ${options.projectNamePascalCase}().lucia().definePergelNitroMiddleware({
export default ${options.projectNameCamelCaseWithPergel}().lucia().definePergelNitroMiddleware({
lucia: auth,
})
`,
Expand All @@ -125,6 +125,15 @@ export default ${options.projectNamePascalCase}().lucia().definePergelNitroMiddl
'definePergelNitroMiddleware',
],
},
{
from: `${options.serverDir}`,
imports: [
{
as: `${options.projectNameCamelCase}Auth`,
name: 'auth',
},
],
},
],
})

Expand Down

0 comments on commit 725c026

Please sign in to comment.