Skip to content

Commit 3a18102

Browse files
committed
feat(auth): allow customizing cookie options
Close #1458
1 parent 027dc9d commit 3a18102

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

packages/nuxt/src/module.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
8484
nuxt.options.runtimeConfig.public.vuefire.config = _options.config
8585
nuxt.options.runtimeConfig.public.vuefire.appCheck = options.appCheck
8686

87+
// server only options
8788
nuxt.options.runtimeConfig.vuefire ??= {}
8889
markRaw(nuxt.options.runtimeConfig.vuefire)
8990
nuxt.options.runtimeConfig.vuefire.admin ??= options.admin
91+
// allows getting the session cookie options
92+
nuxt.options.runtimeConfig.vuefire.auth ??= options.auth
9093

9194
// configure transpilation
9295
const { resolve } = createResolver(import.meta.url)
@@ -173,8 +176,6 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
173176
addPluginTemplate({
174177
src: normalize(resolve(templatesDir, 'plugin.ejs')),
175178
options: {
176-
// FIXME: not needed
177-
...options,
178179
ssr: nuxt.options.ssr,
179180
},
180181
})
@@ -384,6 +385,12 @@ interface VueFireRuntimeConfig {
384385
* @internal
385386
*/
386387
admin?: VueFireNuxtModuleOptionsResolved['admin']
388+
389+
/**
390+
* Authentication options.
391+
* @internal
392+
*/
393+
auth?: VueFireNuxtModuleOptionsResolved['auth']
387394
}
388395
}
389396

packages/nuxt/src/module/options.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,30 @@ export interface VueFireNuxtModuleOptions {
7171
* permissions on your Google Cloud project. You can find more information about what happens behind the scenes
7272
* in Firebase docs: [Manage Session Cookies](https://firebase.google.com/docs/auth/admin/manage-cookies).
7373
*/
74-
sessionCookie?: boolean
74+
sessionCookie?:
75+
| boolean
76+
| {
77+
/**
78+
* maxAge property of the cookie. Defaults to 5 days.
79+
*/
80+
maxAge?: number
81+
/**
82+
* Whether to use a secure cookie. Defaults to `true`.
83+
*/
84+
secure?: boolean
85+
/**
86+
* Whether to use a httpOnly cookie. Defaults to `true`.
87+
*/
88+
httpOnly?: boolean
89+
/**
90+
* The path of the cookie. Defaults to `/`.
91+
*/
92+
path: string
93+
/**
94+
* The sameSite property of the cookie. Defaults to `lax`.
95+
*/
96+
sameSite: 'lax' | 'strict' | 'none'
97+
}
7598
} & VueFireNuxtAuthDependencies)
7699

77100
/**

packages/nuxt/src/runtime/auth/api.session-verification.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export default defineEventHandler(async (event) => {
4949
httpOnly: true,
5050
path: '/',
5151
sameSite: 'lax',
52+
// add user overrides
53+
...(typeof runtimeConfig.vuefire?.auth?.sessionCookie === 'object'
54+
? runtimeConfig.vuefire?.auth?.sessionCookie
55+
: {}),
5256
})
5357
setResponseStatus(event, 201)
5458
return ''

0 commit comments

Comments
 (0)