Skip to content

useAuth

反应式 Firebase 身份验证 结合。它提供了反应式 userisAuthenticated,因此你可以轻松地对用户身份验证状态的变化做出反应。

¥Reactive Firebase Auth binding. It provides a reactive user and isAuthenticated so you can easily react to changes in the users' authentication status. Available in the @vueuse/firebase add-on.

用法

¥Usage

vue
<script setup lang="ts">
import { 
useAuth
} from '@vueuse/firebase/useAuth'
import {
initializeApp
} from 'firebase/app'
import {
getAuth
,
GoogleAuthProvider
,
signInWithPopup
} from 'firebase/auth'
const
app
=
initializeApp
({ /* config */ })
const
auth
=
getAuth
(
app
)
const {
isAuthenticated
,
user
} =
useAuth
(
auth
)
const
signIn
= () =>
signInWithPopup
(
auth
, new
GoogleAuthProvider
())
</script> <template> <
pre
v-if="
isAuthenticated
">{{
user
}}</
pre
>
<
div
v-else>
<
button
@
click
="
signIn
">
Sign In with Google </
button
>
</
div
>
</template>