Skip to content

Commit

Permalink
fix: leverage NUXT_SESSION_PASSWORD provided at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Feb 26, 2024
1 parent a74c869 commit 4932959
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export default defineNuxtModule<ModuleOptions>({
if (!envContent.includes('NUXT_SESSION_PASSWORD')) {
await writeFile(envPath, `${envContent ? envContent + '\n' : envContent}NUXT_SESSION_PASSWORD=${runtimeConfig.session.password}`, 'utf-8')
}
} else if (!nuxt.options._prepare && !runtimeConfig.session.password) {
throw new Error('NUXT_SESSION_PASSWORD environment variable or runtimeConfig.session.password not set')
}

// OAuth settings
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/server/utils/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ export async function requireUserSession(event: H3Event): Promise<UserSession &
return userSession as UserSession & { user: User }
}

const sessionConfig = useRuntimeConfig().session as SessionConfig
let sessionConfig: SessionConfig

function _useSession (event: H3Event) {
if (!sessionConfig) {
// @ts-ignore
sessionConfig = defu({ password: process.env.NUXT_SESSION_PASSWORD }, useRuntimeConfig(event).session)
}
return useSession<UserSession>(event, sessionConfig)
}

0 comments on commit 4932959

Please sign in to comment.