Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
Firebase auth JS with Flask

I am struggling to understand Firebase authentication on the client/server side and have the question below.

I have a login.html page with a login-form and submit button. On the button click event, I have a JavaScript to do some client validation and perform the authentication):

btnSignIn.addEventListener('click', e => {
    // Get email/pass
    const email = inputEmail.value;
    const pass = inputPassword.value;
    /* to-do some validation and then sign in */
    // Sign in
    const promise = firebase.auth().signInWithEmailAndPassword(email, pass)
    promise.catch(e => console.log(e.message))
    }            
});

This is working great so far. Now, once the user has logged in, I want to redirect to home.html page but since this page should be protected by authorized users, do I need to send the token to the server (which is a Flask app)?

How do I send the token from JS to my Flask app? I saw in the Firebase docs that the way to go is via ajax. From the documentation, this is how I should send the token but I am not sure how to implement it.

firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
  // Send token to your backend via HTTPS
  // ...
}).catch(function(error) {
  // Handle error
});

My test Flask app:

@app.route('/')
@app.route('/home')
def home():
    return render_template("home.html")

@app.route('/login', methods=['GET', 'POST'])
def login():
    return render_template("login.html")
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You cannot simply transfer the token from your js code into flask.

What I suggest you do is implement firebase in your backend python code instead of your frontend js code. To start using the python firebase sdk, I recommend either using the docs. That link points to the authentication docs, since your question is authentication related. You should select python as the type of code you would like to work with when viewing the docs.

Here is a youtube video as well on firebase authentication with flask that I really liked: https://www.youtube.com/watch?v=FCw5PFDb99k

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda