0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

getAuthとinitializeAuth ~expo router web~

Posted at

備忘録的にかいていきます

背景

expoでfirebaseと連携するweb/ios/andoroidアプリの勉強をしていた時

config.ts
const auth = initializeAuth(app, {
  persistence: getReactNativePersistence(ReactNativeAsyncStorage)
})

の状態でnpx start --clearしてwebを開くと

Uncaught Error
(0 , _auth.getReactNativePersistence) is not a function

が出た

一応の解決策

expo公式ドキュメント参照

firebaseConfigの作成

.
|_src
  |_app/
  |_config.ts

.
|_src
|  |_app/
|_firebaseConfig.js

にする
中身はJS SDKのnpm

app,auth,db

authとdbは変わらないが初期化メソッドはinitializeAuthからgetAuthに変えた
npx expo start --clearでiOS/Androidを開くとwarningで以下の内容が表示されたが期待通りの動きをしてくれた

 WARN  [2025-05-25T08:12:32.917Z]  @firebase/auth: Auth (11.8.0): 
You are initializing Firebase Auth for React Native without providing
AsyncStorage. Auth state will default to memory persistence and will not
persist between sessions. In order to persist auth state, install the package
"@react-native-async-storage/async-storage" and provide it to
initializeAuth:

import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
const auth = initializeAuth(app, {
  persistence: getReactNativePersistence(ReactNativeAsyncStorage)
});

これはどういうwarning?

AsyncStorage を提供せずに、React Native 用の Firebase Auth を初期化
Auth の状態はデフォルトでメモリ永続化され、セッション間で永続化されません。
Authの状態を永続化するには、
"@react-native-async-storage/async-storage "パッケージをインストールし、
initializeAuthに提供します:

つまり認証状態はずっとメモリにあるよ,メモリをクリアしな限りauthの状態は維持されるって言ってるくさい

これで困ることは大量の顧客の運用レベルになりそうなので個人,小規模開発では無視して良さそう?

割と情報が錯綜していたので,ログインできて動けばとりあえずいいか

ツッコミ,指摘大歓迎です

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?