Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
How to get the promise state when creating a new Auth user in firebase using javascript

I am able to create a new user in firebase Authentication like this:

const status = firebase.auth().createUserWithEmailAndPassword(email, password);   
console.log(status);

The console shows the output as this:

Promise {<pending>}
[[Prototype]]: Promise
[[PromiseState]]: "rejected"
[[PromiseResult]]: FirebaseError: Firebase: The email address is badly formatted.

How would I get the PromiseState from my status variable?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The promise state is whether the promise resolves or rejects. If you're using the .then approach to working with promises, you can supply a second callback function to handle the error case:

firebase.auth().createUserWithEmailAndPassword(email, password)
  .then(status => {
    // If it gets to here, the promise resolved
    console.log(status);
  }, error => {
    // If it gets to here, the promise rejected
    console.log(error);
  });

// Or, equivalently:
firebase.auth().createUserWithEmailAndPassword(email, password)
  .then(status => {
    console.log(status);
  })
  .catch(error => {
    console.log(error);
  });

If you're using async/await, then you handle the error case with a try/catch

async someFunction() {
  try {
    const status = await firebase.auth().createUserWithEmailAndPassword(email, password);
    // If it gets to here, the promise resolved
    console.log(status);
  } catch (error) {
    // If it gets to here, the promise rejected
    console.log(error);
  }
}
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!