• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

242
Views
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 3 years ago · Juan Pablo Isaza
1 answers
Answer question

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 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error