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

335
Vistas
How do I send oauth token and user information from server back to client?

I am trying to implement google oauth in my app. I have a link to a google login page, which on successful completion of the form redirects to my server express route(see below). The controller for this route needs to do ONE of the following:

  • Send the generated token and user information back to the front end so it can be saved in session local storage -> follow up below

  • somehow save this information to the session and then redirect the user to home page

Route controller:

export const googleAuth = async (req, res) => {
  const googleUser = await getGoogleUser({ code: req.query.code });
  let user = await User.findOne({ email: String(googleUser.email) });

  if (!user) {
    user = new User();
  }

  try {
    const token = jwt.sign({ _id: user._id }, process.env.JWT_SECRET, {
      expiresIn: "1d",
    });
    user.password = undefined;
    res.json({ token, user });
  } catch (err) {
    console.log(err);
    return res.status(400).send("Error. Try again.");
  }
};

if the solution is to send the data from backend -> client, how do i receive the data? In my regular authentication method i have a handleSubmit function, but the client has no form submit for google oauth(it's just a link to the google form)

Thanks in advance and sorry if this is a duplicate, I couldn't find a question that answered all these questions together.

about 4 years ago · Juan Pablo Isaza
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