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

99
Views
Handling Firebase auth authentication

I need some help understanding if I am handling the authentication/authorization correctly with Firebase Auth, JS and Python.

Once the user has signed in, I capture the idToken and create a cookie in the browser:

firebase.auth().signInWithEmailAndPassword(email, pass)
.then(({user}) => {
    return user.getIdToken().then((idToken) => {
        if (idToken) {
            document.cookie = "token=" + idToken;
            window.location.assign('/profile');
        } else {
            document.cookie = "token="
        }
    })                    
})
.catch((error) => {
    //handle error here
});

The route /profile should be protected so I created a decorator and I retrieve the cookie and verify it:

id_token = request.cookies.get("token")

if not id_token:
    return redirect(url_for('login'))
try:
    decoded_token = auth.verify_id_token(id_token)
    uid = decoded_token['uid']
except Exception as e:
    print("Exception: {}".format(e))
    return redirect(url_for('login'))

This is working so far but I want to see if this is the ideal situation from a security perspective. Also, what about the onAuthStateChanged? How should I handle it in the case above?

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

0

Firebase SDKs send the ID token with each request in the Authorization header, so sending it in a cookie is not going to more or less dangerous than that.

Instead of determining the token in signInWithEmailAndPassword though, I'd instead monitor ID token generation by listening to onIdTokenChanged events and using that moment to update your cookie.

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!