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

192
Visualizações
How to implement this in node.js?

I have the following request handler that would sign in a user with Firebase. Upon successful login, I'd like to redirect the user to another page.

Would I change window.location to another page within the (document).ready() javascript function? Or would I implement the change here, with a res.redirect (that I did try) but nothing happened, I just got back a status code within the console.

app.post('/api/sign-in', function (req, res, next) {
    firebase.auth().signInWithEmailAndPassword(req.body.email, req.body.password).then(function (user) {
        console.log('a new user has signed in! their e-mail address: ' + user.email + ' | User ID: ' + user.uid)
    }).catch(function (error) {
        console.log(error)
    })
})

Call:

$("#sign-in").on('click', function (event) {
    event.preventDefault()
    $.ajax({
        url: '/api/sign-in',
        method: 'POST',
        data: {
            email: $('#email').val(),
            password: $('#password').val()
        }
    });
});
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Like George said, if you are doing a ajax post it won't redirect.

Maybe something like this could help you:

app.post('/api/sign-in', function (req, res, next) {
firebase.auth().signInWithEmailAndPassword(req.body.email, req.body.password).then(function (user) {
    res.send({ redirect: '/profile' })
}).catch(function (error) {
    console.log(error)
})})

Javascript:

$(document).ready(function () {
        $('#sign-in').click(function () {
            event.preventDefault()
            $.ajax({
                url: '/api/sign-in',
                method: 'POST',
                dataType: 'json',
                success: function (data, textStatus, jqXHR) {
                    if (typeof data.redirect === 'string') {
                        window.location = data.redirect;
                    }
                }
            });
        });
    });

Hope it can be useful.

over 4 years ago · Santiago Trujillo 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