firebase Firestore数据库中未显示Firestore集合

tzdcorbm  于 2023-01-31  发布在  其他
关注(0)|答案(1)|浏览(182)

我将按照此视频创建React/Firestore聊天应用程序:https://youtu.be/k4mjF4sPITE
当我尝试在视频中创建“用户”集合时,集合没有生成。当我在云控制台中查看这些选项卡时,用户正在进行身份验证和存储,但没有作为集合存储在数据库中。以下是我从firebase.js中获得的代码:

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getStorage } from "firebase/storage";
import { getFirestore } from 'firebase/firestore'


const firebaseConfig = {
  apiKey: 'removed',
  authDomain: "removed",
  projectId: "removed",
  storageBucket: "removed",
  messagingSenderId: "removed",
  appId: "removed"
};

// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const auth = getAuth()
export const storage = getStorage();
export const db = getFirestore();`

下面是相关部分的代码:

import React from 'react'
import { useState} from 'react'
import add from '../img/add.png'
import { createUserWithEmailAndPassword, updateProfile } from 'firebase/auth'
import { auth,storage, db } from '../firebase'
import { ref, uploadBytesResumable, getDownloadURL } from "firebase/storage";
import { doc, setDoc } from "firebase/firestore"; 
import { useNavigate } from 'react-router-dom'

export const  Register=() => {
const [err, setErr] = useState(false)
const navigate = useNavigate();

const handleSubmit = async (e) => {
    e.preventDefault();
    const displayName = e.target[0].value;
    const email = e.target[1].value;
    const password = e.target[2].value;
    const file = e.target[3].files[0];

    console.log(displayName, email, password)
try{
    //creates users
   const res= await createUserWithEmailAndPassword(auth, email, password);

   //create references so users can upload images
  const storageRef = ref(storage, displayName);
   
   const uploadTask = uploadBytesResumable(storageRef, file);
   

   uploadTask.on((error) => {
    setErr(true)
     }, 
     (error) => {
     }, 
     () => {
       getDownloadURL(uploadTask.snapshot.ref).then( async(downloadURL) => {
         await updateProfile(res.user, {
            displayName,
            photoURL: downloadURL,
         }) 
    await setDoc(doc(db, "users", res.user.uid), {
    uid: res.user.uid,
    displayName,
    email,
    photoURL: downloadURL,
});

我尝试过的解决方案:

92dk7w1h

92dk7w1h1#

确保在Firebase控制台中启动firestore,并且控制台中没有错误。

相关问题