Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useAuth.md
1---2category: '@Firebase'3---45# useAuth67Reactive [Firebase Auth](https://firebase.google.com/docs/auth) binding. It provides a reactive `user` and `isAuthenticated` so you8can easily react to changes in the users' authentication status.910## Usage1112```vue13<script setup lang="ts">14import { useAuth } from '@vueuse/firebase/useAuth'15import { initializeApp } from 'firebase/app'16import { getAuth, GoogleAuthProvider, signInWithPopup } from 'firebase/auth'1718const app = initializeApp({ /* config */ })19const auth = getAuth(app)20const { isAuthenticated, user } = useAuth(auth)2122const signIn = () => signInWithPopup(auth, new GoogleAuthProvider())23</script>2425<template>26<pre v-if="isAuthenticated">{{ user }}</pre>27<div v-else>28<button @click="signIn">29Sign In with Google30</button>31</div>32</template>33```3435## Return Values3637| Name | Type | Description |38| ----------------- | ---------------------- | --------------------------------------------------------- |39| `user` | `Ref<User \| null>` | The current Firebase user, or `null` if not authenticated |40| `isAuthenticated` | `ComputedRef<boolean>` | Whether a user is currently authenticated |4142The composable automatically updates when the user's ID token changes (including sign-in, sign-out, and token refresh events) using Firebase's `onIdTokenChanged` listener.4344## Type Declarations4546```ts47export interface UseFirebaseAuthOptions {48isAuthenticated: ComputedRef<boolean>49user: Ref<User | null>50}51/**52* Reactive Firebase Auth binding53*54* @see https://vueuse.org/useAuth55*56* @__NO_SIDE_EFFECTS__57*/58export declare function useAuth(auth: Auth): {59isAuthenticated: ComputedRef<boolean>60user: Ref<61{62readonly emailVerified: boolean63readonly isAnonymous: boolean64readonly metadata: {65readonly creationTime?: string | undefined66readonly lastSignInTime?: string | undefined67}68readonly providerData: {69readonly displayName: string | null70readonly email: string | null71readonly phoneNumber: string | null72readonly photoURL: string | null73readonly providerId: string74readonly uid: string75}[]76readonly refreshToken: string77readonly tenantId: string | null78delete: () => Promise<void>79getIdToken: (forceRefresh?: boolean) => Promise<string>80getIdTokenResult: (forceRefresh?: boolean) => Promise<IdTokenResult>81reload: () => Promise<void>82toJSON: () => object83readonly displayName: string | null84readonly email: string | null85readonly phoneNumber: string | null86readonly photoURL: string | null87readonly providerId: string88readonly uid: string89} | null,90| User91| {92readonly emailVerified: boolean93readonly isAnonymous: boolean94readonly metadata: {95readonly creationTime?: string | undefined96readonly lastSignInTime?: string | undefined97}98readonly providerData: {99readonly displayName: string | null100readonly email: string | null101readonly phoneNumber: string | null102readonly photoURL: string | null103readonly providerId: string104readonly uid: string105}[]106readonly refreshToken: string107readonly tenantId: string | null108delete: () => Promise<void>109getIdToken: (forceRefresh?: boolean) => Promise<string>110getIdTokenResult: (forceRefresh?: boolean) => Promise<IdTokenResult>111reload: () => Promise<void>112toJSON: () => object113readonly displayName: string | null114readonly email: string | null115readonly phoneNumber: string | null116readonly photoURL: string | null117readonly providerId: string118readonly uid: string119}120| null121>122}123```124