Skip to content

Commit 501380e

Browse files
committed
docs: add authentication
1 parent 8bd023a commit 501380e

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

docs/.vitepress/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export default defineConfig({
130130
text: 'Options API',
131131
link: '/guide/options-api-realtime-data',
132132
},
133+
{
134+
text: 'Authentication',
135+
link: '/guide/auth',
136+
},
133137
{
134138
text: 'SSR',
135139
link: '/guide/ssr',

docs/guide/auth.md

+48-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
11
# Firebase Authentication
22

3-
WIP
3+
VueFire exposes the current user as a reactive variable while allowing you to use the Firebase Authentication API as you would normally do.
4+
5+
## Installation
6+
7+
Start by adding the `VueFireAuth` module to the `VueFire` plugin:
8+
9+
```ts
10+
app
11+
.use(VueFire, {
12+
firebaseApp: createFirebaseApp(),
13+
modules: [
14+
// ... other modules
15+
VueFireAuth(),
16+
],
17+
})
18+
```
19+
20+
## Get the Current User
21+
22+
You can get the current user as a reactive variable with the `useCurrentUser()` composable:
23+
24+
```vue
25+
<script setup>
26+
import { useCurrentUser } from 'vuefire'
27+
28+
const user = useCurrentUser()
29+
</script>
30+
31+
<template>
32+
<p v-if="user">Hello {{ user.providerData.displayName }}</p>
33+
</template>
34+
```
35+
36+
## Wait for the user to be loaded
37+
38+
There is also a `getCurrentUser()` function that returns a promise of the current user. This is useful if you want to wait for the user to be loaded before doing anything. You can, for example, await it within a navigation guard:
39+
40+
```ts
41+
router.beforeEach(async () => {
42+
await getCurrentUser()
43+
})
44+
```
45+
46+
:::tip
47+
If you are using `getCurrentUser()` in a navigation guard, make sure to add it before calling `app.use(router)` as that will trigger the initial navigation.
48+
:::
49+
50+
Once the user is loaded, `getCurrentUser()` will immediately resolve the current user.

0 commit comments

Comments
 (0)