Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

241
Visualizações
Adding new user information from Firebase v8 to v9

I have a code to create user with image and username to Firebase v8 and I can't replace it to Firebase v9.

Can someone help me? Thank you!

    import { useState, useEffect } from 'react'
    import { projectAuth, projectStorage, projectFirestore } from '../firebase/config'
    import { useAuthContext } from './useAuthContext'
    
    export const useSignup = () => {
      const [isCancelled, setIsCancelled] = useState(false)
      const [error, setError] = useState(null)
      const [isPending, setIsPending] = useState(f`enter code here`alse)
      const { dispatch } = useAuthContext()
    
    
          // upload user thumbnail
          const uploadPath = `thumbnails/${res.user.uid}/${thumbnail.name}`
          const img = await projectStorage.ref(uploadPath).put(thumbnail)
          const imgUrl = await img.ref.getDownloadURL()
    
          // add display AND PHOTO_URL name to user
          await res.user.updateProfile({ displayName, photoURL: imgUrl })
    
        
    
         
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

import {st, db} from '../firebase/config'
import { getDownloadURL, ref, uploadBytesResumable } from 'firebase/storage';
import { doc, setDoc } from 'firebase/firestore';

const _storageRef = ref(st, "thumbnails/" + res.user.uid + "/" + thumbnail.name)
const _uploadTask = uploadBytesResumable(_storageRef, file);

_uploadTask.on("state_changed", (snapshot) => {
    console.log((snapshot.bytesTransferred/snapshot.totalBytes) * 100)
},(error) => {
    console.error(error)
}, async () => {
    await getDownloadURL(_storageRef)
          .then((url) => {
               //update database with the new image url
               console.log(url)
               //setDoc(doc(db, "users", uid), {
               //      photoURL: url
               //   }, {merge: true}) <- to not erase the rest of the values like displayName
          })
           .catch(error => console.error(error))
})
about 4 years ago · Juan Pablo Isaza Relatório

0

The documentation has examples of both V8 (namespaced) and V9 (Modular) syntax. You can just switch to modular tab for reference. For this case, try refactoring the code as shown below:

import { ref, uploadBytes } from "firebase/storage"
import { updateProfile } from "firebase/auth"

const storageRef = ref(projectStorage, `thumbnails/${res.user.uid}/${thumbnail.name}`);

// 'file' comes from the Blob or File API
// uploadBytes() instead of .put()
uploadBytes(storageRef, file).then(async (snapshot) => {
  console.log('Uploaded a blob or file!');

  // updateProfile() is now a top-level function
  // and not a method on User object
  await updateProfile(res.user, {
    displayName: name
  });
  console.log("User profile updated")
});

Also do ensure that you've initialized auth and storage using getAuth() and getStorage() respectively.

Checkout:

  • Upload files with Cloud Storage on Web

  • Update user profile using Firebase Modular SDK

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda