Skip to content

Commit 66cd6d7

Browse files
committed
build: add server export
1 parent 8d2aa52 commit 66cd6d7

File tree

6 files changed

+105
-4
lines changed

6 files changed

+105
-4
lines changed

build.config.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
import { defineBuildConfig } from 'unbuild'
22

33
export default defineBuildConfig({
4+
entries: [
5+
{
6+
input: './src/index',
7+
name: 'index',
8+
},
9+
{
10+
input: './src/server/index',
11+
name: 'server/index',
12+
},
13+
],
414
declaration: true,
515
externals: [
616
'firebase',
17+
'firebase/auth',
18+
'firebase/app-check',
719
'firebase/firestore',
820
'firebase/database',
21+
'firebase/storage',
922
'@firebase/firestore-types',
1023
'@firebase/database-types',
24+
'firebase-admin',
1125
],
26+
27+
rollup: {
28+
emitCJS: true,
29+
},
30+
31+
// hooks: {
32+
// 'rollup:options': (ctx, options) => {
33+
// if (!Array.isArray(options.output)) {
34+
// options.output = options.output ? [options.output] : []
35+
// }
36+
// options.output.push({
37+
// dir: ctx.options.outDir,
38+
// format: 'cjs',
39+
// entryFileNames: '[name].cjs',
40+
// exports: 'auto',
41+
// externalLiveBindings: false,
42+
// freeze: false,
43+
// })
44+
// },
45+
// },
1246
})

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
".": {
1111
"import": "./dist/index.mjs",
1212
"require": "./dist/index.cjs"
13+
},
14+
"./server": {
15+
"import": "./dist/server/index.mjs",
16+
"require": "./dist/server/index.cjs"
1317
}
1418
},
1519
"main": "./dist/index.cjs",
@@ -76,6 +80,7 @@
7680
"enquirer": "^2.3.6",
7781
"execa": "^6.1.0",
7882
"firebase": "^9.14.0",
83+
"firebase-admin": "^11.3.0",
7984
"focus-visible": "^5.2.0",
8085
"happy-dom": "^7.7.0",
8186
"lint-staged": "^13.0.4",

packages/nuxt/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@nuxtjs/eslint-config-typescript": "^12.0.0",
4444
"eslint": "^8.28.0",
4545
"firebase": "^9.14.0",
46+
"firebase-admin": "^11.3.0",
4647
"nuxt": "^3.0.0",
4748
"vuefire": "workspace:*"
4849
}

pnpm-lock.yaml

Lines changed: 29 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server/app-check.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { app } from 'firebase-admin'
2+
import { CustomProvider, initializeAppCheck } from 'firebase/app-check'
3+
4+
/**
5+
* Adds AppCheck using the Firebase Admin SDK. This is necessary on the Server if you have configured AppCheck on the
6+
* client.
7+
*
8+
* @param adminApp - firebase-admin app
9+
* @param appId - appId option passed to firebase/app initializeApp()
10+
* @param param2 options
11+
*/
12+
export function VueFireAppCheckServer(
13+
adminApp: app.App,
14+
appId: string,
15+
{
16+
// default to 1 week
17+
ttlMillis = 604_800_000,
18+
}: {
19+
ttlMillis?: number
20+
} = {}
21+
) {
22+
initializeAppCheck(undefined, {
23+
provider: new CustomProvider({
24+
getToken: () =>
25+
adminApp
26+
.appCheck()
27+
.createToken(appId, { ttlMillis })
28+
.then(({ token, ttlMillis: expireTimeMillis }) => ({
29+
token,
30+
expireTimeMillis,
31+
})),
32+
}),
33+
isTokenAutoRefreshEnabled: false,
34+
})
35+
}

src/server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { VueFireAppCheckServer } from './app-check'

0 commit comments

Comments
 (0)