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

307
Visualizações
How do i input database in firestore with user's input for name of the document?

I have a problem with my api. I want to use the firestore to input data for login & register with APi. Then, when i want to add the document database with user's input email when register but the output is error. my reasons for adding document with user's email is for easier for the next login step for its validation to compare the password also the email. here the code that i already make:

const functions = require("firebase-functions");
const express = require("express");
// eslint-disable-next-line no-unused-vars
const cors = require("cors");

const admin = require("firebase-admin");
admin.initializeApp();

const app = express();
const db = admin.firestore();

app.post("/Register", (req, res) => {
  const {
    name,
    email,
    password,
    phone,
  } = req.body;
  const saldo = 0;
  const valAcc = db.collection("Users").doc(email);
  valAcc.get().then((doc) => {
    if (doc.exists) {
      res.status(409).send("User Already Exist!");
    }
  });
  db.collection("Users").doc(email).add({
    Name: name,
    Email: email,
    Password: password,
    Phone: phone,
    Saldo: saldo,
  });
  res.status(201).send();
});

exports.apptest = functions.https.onRequest(app);

Do you guys have any solution? rly appriciate for any help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don't recommend handling user authentication yourself. I recommend using Firebase built-in tool for this instead: Firebase Authentication

With this, it's easy to implement email/passwords or providers (google, facebook etc) login.

And it's probably much safer than doing from scratch.

Afterwards you can use the UID or email of the logged user for storing/retrieving data on Firestore.

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