Skip to content

Commit 59ad275

Browse files
committed
fix: refactor cookie name var
1 parent b045418 commit 59ad275

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

packages/nuxt/src/runtime/admin/plugin-auth-user.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getCookie } from 'h3'
55
// FirebaseError is an interface here but is a class in firebase/app
66
import type { FirebaseError } from 'firebase-admin'
77
import { log } from '../logging'
8-
import { AUTH_COOKIE_NAME, UserSymbol } from '../constants'
8+
import { UserSymbol } from '../constants'
99
import { defineNuxtPlugin, useRequestEvent } from '#app'
1010

1111
/**
@@ -51,3 +51,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
5151
function isFirebaseError(err: any): err is FirebaseError {
5252
return err != null && 'code' in err
5353
}
54+
55+
// MUST be named session to be kept
56+
// https://firebase.google.com/docs/hosting/manage-cache#using_cookies
57+
const AUTH_COOKIE_NAME = '__session'

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
deleteCookie,
99
} from 'h3'
1010
import { log } from '../logging'
11-
import { AUTH_COOKIE_MAX_AGE, AUTH_COOKIE_NAME } from '../constants'
1211

1312
// This version is used at https://github.com/FirebaseExtended/firebase-framework-tools/blob/e69f5bdd44695274ad88dbb4e21aac778ba60cc8/src/firebase-aware.ts#L39 but doesn't work locally. Should it maybe be used in production only? Seems unlikely.
1413

@@ -66,4 +65,9 @@ export default defineEventHandler(async (event) => {
6665
return ''
6766
})
6867

69-
export const ID_TOKEN_MAX_AGE = 5 * 60
68+
// these must be within this file because the handler gets inlined in dev mode
69+
const ID_TOKEN_MAX_AGE = 5 * 60
70+
const AUTH_COOKIE_MAX_AGE = 60 * 60 * 24 * 5 * 1_000
71+
// MUST be named session to be kept
72+
// https://firebase.google.com/docs/hosting/manage-cache#using_cookies
73+
const AUTH_COOKIE_NAME = '__session'

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
defineEventHandler,
66
deleteCookie,
77
} from 'h3'
8-
import { AUTH_COOKIE_NAME, AUTH_COOKIE_MAX_AGE } from '../constants'
98

109
/**
1110
* Setups an API endpoint to be used by the client to mint a cookie based auth session.
@@ -34,3 +33,9 @@ export default defineEventHandler(async (event) => {
3433
event.node.res.statusCode = 204
3534
return ''
3635
})
36+
37+
// these must be within this file because the handler gets inlined in dev mode
38+
const AUTH_COOKIE_MAX_AGE = 60 * 60 * 24 * 5 * 1_000
39+
// MUST be named session to be kept
40+
// https://firebase.google.com/docs/hosting/manage-cache#using_cookies
41+
const AUTH_COOKIE_NAME = '__session'

packages/nuxt/src/runtime/constants.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,3 @@
22
* @internal Gets access to the user within the application. This is a symbol to keep it private for the moment.
33
*/
44
export const UserSymbol = Symbol('user')
5-
6-
// TODO: customizable defaults
7-
export const AUTH_COOKIE_MAX_AGE = 60 * 60 * 24 * 5 * 1_000
8-
9-
// MUST be named session to be kept
10-
// https://firebase.google.com/docs/hosting/manage-cache#using_cookies
11-
export const AUTH_COOKIE_NAME = '__session'

0 commit comments

Comments
 (0)