PUROGU LADESU

ポエムがメインのブログです。

【Firebase with Expo】プロジェクト作成とログイン

プロジェクト作成

https://console.firebase.google.com/ にアクセスしてプロジェクトを作成する

  1. ウェブアプリに Firebase を追加。アプリ側で apiKey や databaseURL などの設定を行う。
  2. Database -> Database を作成 -> テストモードで開始
  3. Database -> ルール -> allow read write
  4. Authentication -> ログイン方法を設定 -> 匿名
  5. Storage -> 始める -> OK
  6. アプリ側でnpm install firebaseを追加

Authentication

https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user

  • ログイン状態の変更を監視

firebase.auth().onAuthStateChanged(async (user) => {

  • ログインがない場合、匿名ユーザでログインする。

await firebase.auth().signInAnonymously()

  • 現在のユーザを取り出す。

firebase.auth().currentUser