Skip to content

Commit 50a4c53

Browse files
committed
fix: should not import from firebase-admin if not used
1 parent e674bf1 commit 50a4c53

File tree

7 files changed

+30
-25
lines changed

7 files changed

+30
-25
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { createServerUser } from 'vuefire/server'
44
import { getCookie } from 'h3'
55
// FirebaseError is an interface here but is a class in firebase/app
66
import type { FirebaseError } from 'firebase-admin'
7-
import { AUTH_COOKIE_NAME } from '../auth/api.session'
87
import { log } from '../logging'
8+
import { AUTH_COOKIE_NAME, UserSymbol } from '../shared'
99
import { defineNuxtPlugin, useRequestEvent } from '#app'
1010

1111
/**
@@ -42,16 +42,12 @@ export default defineNuxtPlugin(async (nuxtApp) => {
4242

4343
nuxtApp.payload.vuefireUser = user?.toJSON()
4444

45-
// @ts-expect-error: We cannot provide with a Symbol in nuxt and it cannot be typed
46-
nuxtApp[UserSymbol] = createServerUser(user)
45+
nuxtApp[
46+
// we cannot use symbol to index
47+
UserSymbol as unknown as string
48+
] = createServerUser(user)
4749
})
4850

49-
/**
50-
* Gets access to the user within the application. This is a symbol to keep it private for the moment.
51-
* @internal
52-
*/
53-
export const UserSymbol = Symbol('user')
54-
5551
function isFirebaseError(err: any): err is FirebaseError {
5652
return err != null && 'code' in err
5753
}

packages/nuxt/src/runtime/app/plugin.server.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { deleteApp, FirebaseApp, initializeApp } from 'firebase/app'
22
import { User } from 'firebase/auth'
33
import LRU from 'lru-cache'
4-
import { UserSymbol } from '../admin/plugin-auth-user.server'
54
import { log } from '../logging'
5+
import { UserSymbol } from '../shared'
66
import { defineNuxtPlugin, useAppConfig } from '#app'
77

88
// TODO: allow customizing
@@ -26,8 +26,10 @@ const appCache = new LRU<string, FirebaseApp>({
2626
export default defineNuxtPlugin((nuxtApp) => {
2727
const appConfig = useAppConfig()
2828

29-
// @ts-expect-error: this is a private symbol
30-
const user = nuxtApp[UserSymbol] as User | undefined | null
29+
const user = nuxtApp[
30+
// we cannot use a symbol to index
31+
UserSymbol as unknown as string
32+
] as User | undefined | null
3133
const uid = user?.uid
3234

3335
let firebaseApp: FirebaseApp

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import {
66
assertMethod,
77
defineEventHandler,
88
deleteCookie,
9-
sendRedirect,
109
} from 'h3'
1110
import { log } from '../logging'
12-
import { AUTH_COOKIE_MAX_AGE, AUTH_COOKIE_NAME } from './api.session'
11+
import { AUTH_COOKIE_MAX_AGE, AUTH_COOKIE_NAME } from '../shared'
1312

1413
// 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.
1514

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

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

910
/**
1011
* Setups an API endpoint to be used by the client to mint a cookie based auth session.
@@ -33,9 +34,3 @@ export default defineEventHandler(async (event) => {
3334
event.node.res.statusCode = 204
3435
return ''
3536
})
36-
37-
// TODO: customizable defaults
38-
export 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-
export const AUTH_COOKIE_NAME = '__session'

packages/nuxt/src/runtime/auth/plugin.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { FirebaseError, FirebaseApp } from 'firebase/app'
1+
import type { FirebaseApp } from 'firebase/app'
22
import {
33
getAuth,
44
onIdTokenChanged,
55
beforeAuthStateChanged,
66
User,
77
} from 'firebase/auth'
88
import { VueFireAuth } from 'vuefire'
9-
import { defineNuxtPlugin, showError } from '#app'
9+
import { defineNuxtPlugin } from '#app'
1010

1111
/**
1212
* Setups VueFireAuth and automatically mints a cookie based auth session. On the server, it reads the cookie to

packages/nuxt/src/runtime/auth/plugin.server.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import type { FirebaseApp } from 'firebase/app'
22
import type { User } from 'firebase/auth'
33
import { VueFireAuthServer } from 'vuefire/server'
4-
import { UserSymbol } from '../admin/plugin-auth-user.server'
54
import { log } from '../logging'
5+
import { UserSymbol } from '../shared'
66
import { defineNuxtPlugin } from '#app'
77

88
/**
99
* Setups the auth state based on the cookie.
1010
*/
1111
export default defineNuxtPlugin((nuxtApp) => {
1212
const firebaseApp = nuxtApp.$firebaseApp as FirebaseApp
13-
// @ts-expect-error: this is a private symbol
14-
const user = nuxtApp[UserSymbol] as User | undefined | null
13+
const user = nuxtApp[
14+
// we cannot use symbol to index
15+
UserSymbol as unknown as string
16+
] as User | undefined | null
1517

1618
log('debug', 'setting up user for app', firebaseApp.name, user?.uid)
1719

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @internal Gets access to the user within the application. This is a symbol to keep it private for the moment.
3+
*/
4+
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)