useAuth
TIP
このコンポーザブルはクライアントサイド・サーバーサイドの両方で利用できます。
auth インスタンスとリアクティブな currentUserと isAuthenticatedを取得します。getAuth().currentUserと同等の処理を行います。
WARNING
useAuthSSRによってサーバーサイドでユーザーの情報を利用できますが、サーバーサイドで認証されてはいません。例えば、セキュリティールールを設定したFirestoreに対するサーバーサイドからのアクセスは失敗することがあります。クライアントサイドだけでデータにアクセスするか、サーバーサイドではAdmin SDKを使うことを検討してください。
Example
const { auth, currentUser, isAuthenticated } = useAuth();
if (isAuthenticated) {
// `currentUser` は `ref`、`isAuthenticated` は `computed`
console.log(currentUser.value?.displayName)
}
サーバールート(~/server/)で利用する場合は、useAuthではなくuseServerAuthを利用してください。
import { useServerAuth } from '#firebase/server'
const { currentUser, isAuthenticated } = useServerAuth()