Skip to content

useAuth

Category
Export Size
160 B
Package
@vueuse/firebase
Last Changed
2 months ago

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>

Type Declarations

Show Type Declarations
ts
export interface UseFirebaseAuthOptions {
  
isAuthenticated
:
ComputedRef
<boolean>
user
:
Ref
<
User
| null>
} /** * Reactive Firebase Auth binding * * @see https://vueuse.org/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 > }

Source

SourceDocs

Contributors

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

Changelog

v13.6.0 on
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.

Build faster with AI
New Masterclass to help you leverage AI in your Vue workflow
Get Early Access