useAuth

useAuth

リアクティブな Firebase Auth バインディングです。リアクティブな userisAuthenticated を提供し、ユーザーの認証ステータスの変化に簡単に対応できます。

使用方法

<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">
      Googleでサインイン
    </button>
  </div>
</template>