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

275
Views
How to update email and sensitive data properly in Firebase?

I have a code where the user can update his credentials/personal information however I encounter a problem and managed to fix it, it was saying first argument had to be an string and I found a solution however I got an error afterwards saying "This operation is sensitive and requires recent authentication. Log in again before retrying...

enter image description here

Afterwards I found in some of the comments where I found my first solution the following: user.reauthenticateWithCredential(auth.EmailAuthProvider.credential(user.email, user.password)).then(() => user.updateEmail(email)) I tried to use this but is not working I get other error afterwards and wanted to know if this was either outdated or I'm just doing this wrong.

enter image description here

Code

I get my auth from my firebase.js

const db = firebase.firestore();
const auth = firebase.auth();
const storage = firebase.storage();

I get my user from my App.js and then if I need it I just send it just like this:

function App() {

const [user, setUser] = useState([]);

  useEffect(() => {
    auth.onAuthStateChanged((authUser) => {

      if (authUser) {
        setUser(authUser);
      } else {
        setUser(false);
      }
    })
  }, [])

return (
....
<Route path = "/Update_Profile">
            <Inicio user={user}/>
            <UpdateProfile user={user}/>
          </Route>
...
)}

export default App;

const updateEmail = (e) => {
        e.preventDefault();
        
        if (user && (email != "")) {
            user.reauthenticateWithCredential(auth.EmailAuthProvider.credential(user.email, user.password))
            .then(() => user.updateEmail(email))
            
            const ref = db.collection("usuarios").doc(user.uid)
            ref.update({
                email: email
            })
        } else {
            //User is not logged in, handle that case here
        }
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because auth is an instance of the Auth module and not the namespace of the Auth module from the Firebase Web SDK (because you've used const auth = firebase.auth()), the following value is undefined:

auth.EmailAuthProvider

This is because the firebase.auth.Auth class does not define a property EmailAuthProvider. This then means JavaScript tries to call undefined.credential(...) and throws an error.

To access the EmailAuthProvider class, you need to access it from the firebase.auth namespace directly:

firebase.auth.EmailAuthProvider

In short,

firebase.auth !== firebase.auth()
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!