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

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

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 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