The indicated error appears on line //line29, and I am not able to find the error within the code, can someone help me? the code is to show the information of the registered users when it is searched through the cpf;
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
async function GetADocument(){
var Ref = setDoc(db, 'cpf', pesquisa.value);
const docSnap = await getDocs(Ref);
if(docSnap.exists(cpf = pesquisa)){
nome.value = docSnap.data().nome;
endereco.value = docSnap.data().endereco;
bairro.value = docSnap.data().bairro;
cidade.value = docSnap.data().cidade;
uf.value = docSnap.data().uf;
cep.value = docSnap.data().cep;
rg.value = docSnap.data().rg;
cpf.value = docSnap.data().cpf;
nascimento.value = docSnap.data().nascimento;
tel.value = docSnap.data().tel;
cel.value = docSnap.data().cel;
titulo.value = docSnap.data().titulo;
zona.value = docSnap.data().zona;
secao.value = docSnap.data().secao;
pai.value = docSnap.data().pai;
mae.value = docSnap.data().mae;
}
else{
alert("usuário não encontrado");
}
} //line29
btnbuscar.addEventListener("click", GetADocument);
setDoc is used to write a document. If you want to create a DocumentReference you need to use doc.
Try changing
var Ref = setDoc(db, 'cpf', pesquisa.value);
to
var Ref = doc(db, 'cpf', pesquisa.value);
Also, getDocs (with an s) retrieves all documents in a collection. If you just want to fetch a single document you need to use getDoc (without an s).