跳到主要内容

useAuth

分类
导出大小
160 B
@vueuse/firebase
上次更改
3 个月前

响应式的 Firebase Auth 绑定。它提供了一个响应式的 userisAuthenticated,以便您可以轻松响应用户认证状态的变化。可在 @vueuse/firebase 插件中使用。

用法

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>

类型声明

显示类型声明
ts
export interface UseFirebaseAuthOptions {
  
isAuthenticated
:
ComputedRef
<boolean>
user
:
Ref
<
User
| null>
} /** * Reactive Firebase Auth binding * * @see https://vueuse.org.cn/useAuth * * @__NO_SIDE_EFFECTS__ */ export declare function
useAuth
(
auth
:
Auth
): {
isAuthenticated
:
ComputedRef
<boolean>
user
:
Ref
<
{ readonly
emailVerified
: boolean
readonly
isAnonymous
: boolean
readonly
metadata
: {
readonly
creationTime
?: string | undefined
readonly
lastSignInTime
?: string | undefined
} readonly
providerData
: {
readonly
displayName
: string | null
readonly
email
: string | null
readonly
phoneNumber
: string | null
readonly
photoURL
: string | null
readonly
providerId
: string
readonly
uid
: string
}[] readonly
refreshToken
: string
readonly
tenantId
: string | null
delete
: () =>
Promise
<void>
getIdToken
: (
forceRefresh
?: boolean) =>
Promise
<string>
getIdTokenResult
: (
forceRefresh
?: boolean) =>
Promise
<
IdTokenResult
>
reload
: () =>
Promise
<void>
toJSON
: () => object
readonly
displayName
: string | null
readonly
email
: string | null
readonly
phoneNumber
: string | null
readonly
photoURL
: string | null
readonly
providerId
: string
readonly
uid
: string
} | null, |
User
| { readonly
emailVerified
: boolean
readonly
isAnonymous
: boolean
readonly
metadata
: {
readonly
creationTime
?: string | undefined
readonly
lastSignInTime
?: string | undefined
} readonly
providerData
: {
readonly
displayName
: string | null
readonly
email
: string | null
readonly
phoneNumber
: string | null
readonly
photoURL
: string | null
readonly
providerId
: string
readonly
uid
: string
}[] readonly
refreshToken
: string
readonly
tenantId
: string | null
delete
: () =>
Promise
<void>
getIdToken
: (
forceRefresh
?: boolean) =>
Promise
<string>
getIdTokenResult
: (
forceRefresh
?: boolean) =>
Promise
<
IdTokenResult
>
reload
: () =>
Promise
<void>
toJSON
: () => object
readonly
displayName
: string | null
readonly
email
: string | null
readonly
phoneNumber
: string | null
readonly
photoURL
: string | null
readonly
providerId
: string
readonly
uid
: string
} | null > }

来源

源代码文档

贡献者

Anthony Fu
Jacob Clevenger
SerKo
Anthony Fu
Kevin Story
Steven Yung
ordago

更新日志

v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。