Skip to content

Commit b41fffc

Browse files
committed
docs: improvements
1 parent 7c1ce18 commit b41fffc

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function sidebarGuide(): SidebarGroup {
153153
link: '/guide/auth',
154154
},
155155
{
156-
text: 'File Storage',
156+
text: 'Storage',
157157
link: '/guide/storage',
158158
},
159159
{

docs/guide/auth.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ import {
4141
} from 'firebase/auth'
4242
import { useCurrentUser, useFirebaseAuth } from 'vuefire'
4343
44-
const auth = useFirebaseAuth()! // only exists on client side
44+
const auth = useFirebaseAuth() // only exists on client side
4545
4646
// display errors if any
47-
const error = ref<Error | null>(null)
47+
const error = ref(null)
4848
function signinRedirect() {
4949
signInWithRedirect(auth, someAuthProvider).catch((reason) => {
5050
console.error('Failed signinRedirect', reason)
@@ -83,7 +83,7 @@ const auth = useFirebaseAuth()!
8383
There are multiple ways to add the auth providers to your app like exporting a `new GoogleAuthProvider()` instance from the file where we initialize Firebase. Another way is to create it directly in the component where you need it. make sure to add it into a regular `<script>` since each `<script setup>` is scoped to a component instance:
8484

8585
```vue{1-4,17}
86-
<script lang="ts">
86+
<script>
8787
import { GoogleAuthProvider } from 'firebase/auth'
8888
export const googleAuthProvider = new GoogleAuthProvider()
8989
</script>
@@ -131,16 +131,18 @@ There is also a `getCurrentUser()` function that returns a promise of the curren
131131

132132
```ts
133133
router.beforeEach(async (to) => {
134-
// routes with `meta: { requiresAuth: true }` will check for the users, others won't
134+
// routes with `meta: { requiresAuth: true }` will check for
135+
// the users, others won't
135136
if (to.meta.requiresAuth) {
136137
const currentUser = await getCurrentUser()
137138
// if the user is not logged in, redirect to the login page
138139
if (!currentUser) {
139140
return {
140141
path: '/login',
141142
query: {
142-
// we keep the current path in the query so we can redirect to it after login
143-
// with `router.push(route.query.redirect || '/')`
143+
// we keep the current path in the query so we can
144+
// redirect to it after login with
145+
// `router.push(route.query.redirect || '/')`
144146
redirect: to.fullPath,
145147
},
146148
}

docs/guide/realtime-data.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,9 @@ const todoList = useDocument(
386386
})
387387
)
388388
```
389+
390+
::: warning
391+
392+
While you can return pretty much anything in `withConverter()`, **if you are using [SSR](./ssr.md)**, make sure you object is serializable. For example, you can't return custom classes or functions.
393+
394+
:::

docs/guide/ssr.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ export const install: UserModule = ({ isClient, initialState, app }) => {
7171
}
7272
```
7373

74-
Note that by default, vite-ssg (used by Vitesse) uses `JSON.stringify()` to serialize the state, which is faster but doesn't support some values like `Date` objects and also exposes your application to some attacks **if your data comes from the user**. You can use a custom `transformState` function to handle this:
74+
Note that by default, vite-ssg (used by Vitesse) uses `JSON.stringify()` to serialize the state, which is faster but doesn't support some values like `TimeStamp` and `GeoPoint` objects and also exposes your application to some attacks **if your data comes from the user**. You can use a custom `transformState` function to handle this:
7575

76-
```ts
76+
```ts{6-9,18-22}
7777
// src/main.ts
7878
// https://github.com/Rich-Harris/devalue#usage
7979
import devalue from 'devalue'
8080
import { ViteSSG } from 'vite-ssg'
8181
import App from './App.vue'
82+
import {
83+
devalueCustomParsers,
84+
devalueCustomStringifiers,
85+
} from 'vuefire'
8286
8387
export const createApp = ViteSSG(
8488
App,
@@ -88,12 +92,18 @@ export const createApp = ViteSSG(
8892
},
8993
{
9094
transformState(state) {
91-
return import.meta.env.SSR ? devalue.stringify(state) : devalue.parse(state)
95+
return import.meta.env.SSR
96+
? devalue.stringify(state, devalueCustomStringifiers)
97+
: devalue.parse(state, devalueCustomParsers)
9298
},
93-
},
99+
}
94100
)
95101
```
96102

103+
::: tip
104+
This is handled out of the box with the [`nuxt-vuefire` plugin in Nuxt projects](../nuxt/getting-started.md).
105+
:::
106+
97107
Web Security is a broad topic that we cannot cover here. We recommend you to read these resources to dive deeper:
98108

99109
- [State Serialization in vite-ssg](https://github.com/antfu/vite-ssg#state-serialization)
@@ -147,7 +157,7 @@ import { usePendingPromises } from 'vuefire'
147157
// this store internally calls `useDocument()` when created
148158
const quizStore = useQuizStore()
149159
150-
// since `useDocument()` has been called
160+
// since `useDocument()` has been called
151161
await usePendingPromises()
152162
</script>
153163
```
@@ -166,7 +176,7 @@ This only works if you avoid rendering on server these documents or collections.
166176

167177
<!-- TODO: I wonder if we could attach effect scopes to applications so `onServerPrefetch()` is still awaited when attached -->
168178

169-
<!--
179+
<!--
170180
171181
## Vue Router Data Loaders
172182

docs/nuxt/auth.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# Authentication
22

3-
Nuxt VueFire integrates with [Firebase Authentication](https://firebase.google.com/docs/auth) module to automatically synchronize the current user state on the server and the client.
3+
Nuxt VueFire integrates with [Firebase Authentication](https://firebase.google.com/docs/auth) module to automatically synchronize the current user state on the server and the client. Activate this module by setting the `vuefire.auth` to `true` in `nuxt.config.ts`:
4+
5+
```ts{5}
6+
export default defineNuxtConfig({
7+
// ...
8+
vuefire: {
9+
// ensures the auth module is enabled
10+
auth: true,
11+
config: {
12+
// ...
13+
}
14+
},
15+
})
16+
```
417

518
You can access the current user with the `useCurrentUser()` composable within any component:
619

docs/nuxt/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ echo service-account.json >> .gitignore
8686

8787
If you are using the [Authentication](https://firebase.google.com/docs/auth) module or [AppCheck](https://firebase.google.com/docs/app-check), make sure to enable them as well:
8888

89-
```ts{3-14}
89+
```ts{5,6-13}
9090
export default defineNuxtConfig({
9191
// ...
9292
vuefire: {

0 commit comments

Comments
 (0)