我不明白问题出在哪里,我什至无法上传测试数据。
firebase.js
import { initializeApp } from 'firebase/app'
import {getAuth} from 'firebase/auth'
const firebaseConfig = {
apiKey: "---",
authDomain: "---",
databaseURL: "---",
projectId: "---",
storageBucket: "---",
messagingSenderId: "---",
appId: "---"
}
// Initialize Firebase and Firebase Authentication
const app = initializeApp(firebaseConfig)
const auth = getAuth(app)
export {auth}
ProfileEdit.js
import { useAuthValue } from './AuthContext'
import { signOut } from 'firebase/auth'
import { getDatabase, ref, child, push, update,set } from "firebase/database";
import React, { useState, useEffect } from 'react';
import xtype from 'xtypejs'
import { auth } from './firebase'
function ProfileEdit() {
const { currentUser } = useAuthValue();
const db = ref(getDatabase());
const [name, setName] = useState()
const [phone, setPhone] = useState()
const [payment, setPayment] = useState()
const [address, setAddress] = useState()
const Submit = () => {
const postData = {
address: "test",
firstName: "test",
paymentByCard: "test",
phone: "test",
};
const data = {}
data["users/" + currentUser?.uid] = postData
console.log(data)
return update(ref(db,data))
}
console.log(currentUser?.uid)
return (
<form action="" className="profile-filling" >
<input type="text" name={"name"} id="" placeholder="Enter your firstname" />
<input type="text" name={"address"} id="" placeholder="Enter your Address" />
<input type="text" name={"phone"} id="" placeholder="Enter your phoneNumber" />
<div>
<span> Credit cart? </span>
<input type="checkBox" name={"payment"} id="" placeholder="Enter your firstname" />
<span>Cahs?</span>
<input type="checkBox" name={"payment"} id="" placeholder="Enter your firstname" />
</div>
<span onClick={Submit}>Submit</span>
</form>
)
}
export default ProfileEdit
换了不同的。我还处理了一些错误用户应该从大写开始。