useAuth
useAuth
リアクティブな Firebase Auth バインディングです。リアクティブな user と isAuthenticated を提供し、ユーザーの認証ステータスの変化に簡単に対応できます。
使用方法
<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>
© 2019–PRESENT Anthony Fu https://github.com/antfu
※このページは Nuxt.js 公式ドキュメントの翻訳ページです。
公式ドキュメントの該当ページはこちら:
#