Skip to content

Commit 9559e71

Browse files
committed
feat(ssr): handles TimeStamps
1 parent 310b146 commit 9559e71

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/nuxt/src/module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
8989
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
9090
const templatesDir = fileURLToPath(new URL('../templates', import.meta.url))
9191

92+
// to handle TimeStamp objects
93+
addPlugin(resolve(runtimeDir, 'payload-plugin'))
94+
9295
// TODO: I don't think the appConfig is the right place to store these as it makes things reactive
9396
// Let plugins and the user access the firebase config within the app
9497
nuxt.options.appConfig.firebaseConfig = markRaw(options.config)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {
2+
definePayloadPlugin,
3+
definePayloadReducer,
4+
definePayloadReviver,
5+
} from '#app'
6+
7+
/**
8+
* Handles Firestore Timestamps and other JSONifiable objects
9+
*/
10+
export default definePayloadPlugin(() => {
11+
definePayloadReducer(
12+
'JSONifiable',
13+
(data: any) =>
14+
data != null &&
15+
typeof data.toJSON === 'function' &&
16+
JSON.stringify(data.toJSON())
17+
)
18+
definePayloadReviver('JSONifiable', (data: string) => JSON.parse(data))
19+
})

0 commit comments

Comments
 (0)