Skip to content

Commit 8480e4f

Browse files
committed
refactor: update nuxt
1 parent 186dc0e commit 8480e4f

File tree

8 files changed

+1240
-2875
lines changed

8 files changed

+1240
-2875
lines changed

packages/nuxt/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dev:prepare": "nuxt-module-build --stub"
3838
},
3939
"dependencies": {
40-
"@nuxt/kit": "^3.0.0",
40+
"@nuxt/kit": "^3.6.2",
4141
"lru-cache": "^10.0.0"
4242
},
4343
"peerDependencies": {
@@ -60,14 +60,14 @@
6060
},
6161
"devDependencies": {
6262
"@firebase/app-types": "^0.9.0",
63-
"@nuxt/module-builder": "^0.2.1",
64-
"@nuxt/schema": "^3.0.0",
63+
"@nuxt/module-builder": "^0.4.0",
64+
"@nuxt/schema": "^3.6.2",
6565
"@nuxtjs/eslint-config-typescript": "^12.0.0",
6666
"eslint": "^8.44.0",
6767
"firebase": "^9.23.0",
6868
"firebase-admin": "^11.9.0",
6969
"firebase-functions": "^4.4.1",
70-
"nuxt": "^3.0.0",
70+
"nuxt": "^3.6.2",
7171
"vuefire": "workspace:*"
7272
}
7373
}

packages/nuxt/playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"prepare": "nuxi prepare"
99
},
1010
"devDependencies": {
11-
"nuxt": "^3.0.0"
11+
"nuxt": "^3.6.2"
1212
},
1313
"dependencies": {
1414
"@firebase/app-types": "^0.9.0",

packages/nuxt/src/firebaseAliases.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// handle aliases of firebase packages until https://github.com/vitejs/vite/issues/11114 is fixed
22

3+
import { join } from 'node:path'
34
import { resolvePath } from '@nuxt/kit'
45

56
/**
@@ -18,10 +19,13 @@ export async function addMissingAlias(
1819
if (!aliases[libToCheck]) {
1920
// this gives an absolute path which is needed for the alias to work since the firebase package is not including the dist folder in exports
2021
const resolvedLibFolder = await resolvePath(libToCheck)
21-
const resolvedLibFile =
22-
resolvedLibFolder.slice(0, resolvedLibFolder.lastIndexOf('dist')) +
23-
'dist/' +
22+
console.log('resolvedLibFolder', libToCheck, resolvedLibFolder)
23+
const resolvedLibFile = join(
24+
resolvedLibFolder.slice(0, resolvedLibFolder.lastIndexOf('dist')),
25+
'dist',
2426
filename
27+
)
28+
console.log('fixedTo', libToCheck, resolvedLibFile)
2529
aliases[libToCheck] = resolvedLibFile
2630
}
2731
}

packages/nuxt/src/module.ts

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,9 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
9494
nuxt.options.appConfig.firebaseConfig = markRaw(options.config)
9595
nuxt.options.appConfig.vuefireOptions = markRaw(options)
9696

97-
// nuxt.options.build.transpile.push(templatesDir)
9897
nuxt.options.build.transpile.push(runtimeDir)
9998
nuxt.options.build.transpile.push(templatesDir)
10099

101-
// FIXME: this is a workaround because of the resolve issue with firebase
102-
// without this, we use different firebase packages within vuefire and nuxt-vuefire
103-
nuxt.options.build.transpile.push('vuefire')
104-
nuxt.options.build.transpile.push('vuefire/server')
105-
106100
// This one is set by servers, we set the GOOGLE_APPLICATION_CREDENTIALS env variable instead that has a lower priority and can be both a path or a JSON string
107101
// process.env.FIREBASE_CONFIG ||= JSON.stringify(options.config)
108102
if (typeof options.admin?.serviceAccount === 'string') {
@@ -238,38 +232,6 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
238232
{ from: 'vuefire', name: 'useDatabaseList' },
239233
{ from: 'vuefire', name: 'useDatabaseObject' },
240234
])
241-
242-
// TODO: refactor
243-
// NOTE: Because of https://github.com/nuxt/framework/issues/9865
244-
// otherwise, move to the `hooks` option
245-
if (nuxt.options.ssr) {
246-
// NOTE: workaround until https://github.com/vitejs/vite/issues/11114 is fixed
247-
// TODO: refactor
248-
nuxt.addHooks({
249-
// Resolve the correct firebase/firestore path on server only since vite is resolving the wrong one in dev
250-
'vite:extendConfig': async (config, { isServer }) => {
251-
config.resolve ??= {}
252-
config.resolve.alias ??= {}
253-
const aliases: Record<string, string> = config.resolve
254-
.alias as Record<string, string>
255-
256-
const promises: Promise<void>[] = []
257-
258-
if (isServer) {
259-
promises.push(
260-
addMissingAlias(aliases, 'firebase/firestore', 'index.mjs')
261-
)
262-
promises.push(
263-
addMissingAlias(aliases, '@firebase/firestore', 'index.node.mjs')
264-
)
265-
}
266-
267-
promises.push(addMissingAlias(aliases, 'firebase/app', 'index.mjs'))
268-
269-
await Promise.all(promises)
270-
},
271-
})
272-
}
273235
},
274236

275237
// workaround for vite
@@ -288,6 +250,9 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
288250
'firebase/auth',
289251
'@firebase/auth',
290252
'@firebase/component',
253+
'firebase-admin/auth',
254+
'firebase-admin/app',
255+
'firebase-admin/app-check',
291256
]
292257
viteInlineConfig.resolve.dedupe.push(...deps)
293258

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
AUTH_COOKIE_NAME,
77
} from 'vuefire/server'
88
import { getCookie } from 'h3'
9-
import { defineNuxtPlugin, useRequestEvent } from '#app'
109
import { UserSymbol } from '../constants'
10+
import { defineNuxtPlugin, useRequestEvent } from '#app'
1111

1212
/**
1313
* Check if there is a cookie and if it is valid, extracts the user from it. This only requires the admin app.
@@ -21,7 +21,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
2121
getCookie(event, AUTH_COOKIE_NAME),
2222
adminApp
2323
)
24-
const user = await (decodedToken && adminAuth.getUser(decodedToken.uid))
24+
const user = await Promise.resolve(
25+
decodedToken && adminAuth.getUser(decodedToken.uid)
26+
)
2527

2628
// expose the user to code
2729
event.context.user = user

0 commit comments

Comments
 (0)