【发布时间】:2022-01-15 17:58:30
【问题描述】:
我现在在这个问题上苦苦挣扎了几天。有人可以根据我的代码提供精确的解决方案。请不要在 firebase 文档中引用 mi,因为它非常不清楚。我不熟悉火力基地。在我的代码中,我知道问题出在 handleReg 方法中。目前,我的用户正在创建中。但是,我的 firebase db 集合中没有写入任何数据。我需要为新用户和他想要存储在 firebase db 集合中的附加数据实现相同的 doc id(uid)。请有人提供精确的解决方案。 Firebase 文档没有提供有关如何执行此操作的明确说明,这非常令人沮丧。我还检查了所有堆栈溢出链接。他们没有为这个问题提供解决方案。请帮助
import React, {useState} from "react";
import { View, Button } from "react-native";
import { TextInput } from "react-native-paper";
import { doc, setDoc, collection, addDoc } from "firebase/firestore";
import { db } from "../firebase/firebase.authentication";
import { auth } from "../firebase/firebase.authentication";
import { createUserWithEmailAndPassword} from "firebase/auth";
export const RegisterScreen = () => {
const [email, setEmail] = useState("");
const [password, setpassword] = useState("");
const HandleReg = () => {
createUserWithEmailAndPassword(auth, email, password)
.then(registredUser => {
const {uid}= registredUser.user.uid
const SetData = async ()=>{
await setDoc(doc(db, "user", uid),{
name:"test"
})
}
})
}
return (
<>
<View>
<TextInput value={email}
onChangeText={(text)=> setEmail(text)}
/>
<TextInput
value={password}
onChangeText={(text)=> setpassword(text)}
/>
<Button title="set" onPress={HandleReg}/>
</View>
</>
);
}
还有我的 Firebase js:
import {initializeApp} from "firebase/app"
import { getAuth} from "firebase/auth";
import {getFirestore } from "firebase/firestore";
const firebaseConfig = {
apiKey: "xx",
authDomain: "xx",
projectId: "xx",
storageBucket: "xx",
messagingSenderId: "xx",
appId: "xx"
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);
【问题讨论】:
标签: javascript firebase react-native google-cloud-firestore firebase-authentication