Skip to content

Commit 366ccc0

Browse files
committed
feat(ssr): fail on unknown provider
1 parent 9d09890 commit 366ccc0

File tree

5 files changed

+56
-23
lines changed

5 files changed

+56
-23
lines changed

docs/cookbook/deployment-nuxt.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ NITRO_PRESET=firebase nuxt build
1010

1111
cd .output/server && pnpm i
1212

13-
Activate app check https://console.developers.google.com/apis/api/iamcredentials.googleapis.com/overview?project=998674887640a
13+
Activate app check <https://console.developers.google.com/apis/api/iamcredentials.googleapis.com/overview?project=998674887640a>

packages/nuxt/playground/firebase.json

+27-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
"**/.*",
1111
"**/node_modules/**"
1212
],
13-
"rewrites": [{ "source": "**", "function": "server" }]
13+
"rewrites": [
14+
{
15+
"source": "**",
16+
"function": "server"
17+
}
18+
]
1419
},
1520
"database": {
1621
"rules": "database.rules.json"
@@ -21,5 +26,26 @@
2126
},
2227
"storage": {
2328
"rules": "storage.rules"
29+
},
30+
"emulators": {
31+
"functions": {
32+
"port": 5001
33+
},
34+
"firestore": {
35+
"port": 8080
36+
},
37+
"database": {
38+
"port": 9050
39+
},
40+
"hosting": {
41+
"port": 5050
42+
},
43+
"storage": {
44+
"port": 9199
45+
},
46+
"ui": {
47+
"enabled": true
48+
},
49+
"singleProjectMode": true
2450
}
2551
}

packages/nuxt/playground/nuxt.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default defineNuxtConfig({
3030
appCheck: {
3131
debug: process.env.NODE_ENV !== 'production',
3232
isTokenAutoRefreshEnabled: true,
33-
provider: 'RecaptchaV3',
33+
provider: 'ReCaptchaV3',
3434
key: '6LfJ0vgiAAAAAHheQE7GQVdG_c9m8xipBESx_SKI',
3535
},
3636

packages/nuxt/src/runtime/plugins/admin.server.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,33 @@ export default defineNuxtPlugin((nuxtApp) => {
1717

1818
// only initialize the admin sdk once
1919
if (!getApps().length) {
20-
const adminApp =
21-
// this is specified when deployed on Firebase and automatically picks up the credentials from env variables
22-
process.env.GCLOUD_PROJECT
23-
? initializeApp()
24-
: initializeApp({
25-
...firebaseAdmin.config,
26-
credential: cert(firebaseAdmin.serviceAccount),
27-
})
28-
29-
if (vuefireOptions.appCheck) {
30-
// NOTE: necessary in VueFireAppCheckServer
31-
if (!firebaseApp.options.appId) {
32-
throw new Error(
33-
'[VueFire]: Missing "appId" in firebase config. This is necessary to use the app-check module on the server.'
34-
)
35-
}
36-
37-
VueFireAppCheckServer(adminApp, firebaseApp)
20+
// this is specified when deployed on Firebase and automatically picks up the credentials from env variables
21+
if (process.env.GCLOUD_PROJECT) {
22+
initializeApp()
23+
} else {
24+
initializeApp({
25+
// TODO: is this really going to be used?
26+
...firebaseAdmin.config,
27+
credential: cert(firebaseAdmin.serviceAccount),
28+
})
3829
}
3930
}
4031

32+
const adminApp = getApp()
33+
if (vuefireOptions.appCheck) {
34+
// NOTE: necessary in VueFireAppCheckServer
35+
if (!firebaseApp.options.appId) {
36+
throw new Error(
37+
'[VueFire]: Missing "appId" in firebase config. This is necessary to use the app-check module on the server.'
38+
)
39+
}
40+
41+
VueFireAppCheckServer(adminApp, firebaseApp)
42+
}
43+
4144
return {
4245
provide: {
43-
adminApp: getApp(),
46+
adminApp,
4447
},
4548
}
4649
})

packages/nuxt/templates/plugin.ejs

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ export default defineNuxtPlugin((nuxtApp) => {
5252
provider: '<%= options.appCheck.provider %>' === 'ReCaptchaV3'
5353
? new ReCaptchaV3Provider('<%= options.appCheck.key %>')
5454
: new CustomProvider({
55-
getToken: () => Promise.resolve({ token: '', expireTimeMillis: 1 })
55+
getToken: () => Promise.reject(
56+
process.env.NODE_ENV !== 'production'
57+
? new Error('Unknown provider "<%= options.appCheck.provider %>"')
58+
: new Error()
59+
),
5660
}),
5761
}))
5862
<% } %>

0 commit comments

Comments
 (0)