FirebaseでRealtime Databaseに入っているユーザーカラムの情報を取ってきたいのですが、なぜか取ってこれません。
下記のやり方にどうも問題があるのでしょうか。
エラーとしては、this.propsがnullでかえってくると入った状態です・・・。
JavaScript
1・・・ 2 componentWillMount() { 3 const { currentUser } = firebase.auth(); 4 5 firebase.database().ref(`/users/${currentUser.uid}`) 6 .once('value', snapshot => { 7 const user = snapshot.val(); 8 return user; 9 }); 10 } 11 12・・・ 13 14 render() { 15 const { user } = this.state; 16 17 // When the user logs out there may be a minor period where the Profile screen is 18 // still displayed. This protects against this scenario. 19 if (!user) { 20 return null; 21 } 22 23 return ( 24 <Screen> 25 <View style={styles.profileContainer}> 26 {user.photoURL 27 ? ( 28 <Image 29 source={{ uri: user.photoURL }} 30 style={[styles.photo, styles.photoImage]} 31 /> 32 ) : ( 33 <Icon 34 active 35 name="account" 36 style={[styles.photo, styles.photoIcon]} 37 /> 38 )} 39 <Text style={styles.nameText}>{user.displayName}</Text> 40 </View> 41・・・
Firebaseのルールは下記です。
"rules": { "users": { "$uid": { ".read": "auth != null", ".write": "$uid === auth.uid", } } }
すみませんが、お助けください・・・汗
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。