Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda