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

280
Vistas
Session in Next.js not returning correct values

After login, some of the data returned does not appear in the session, it only returns the email and name. However, the ID goes below the user object. Also, I have console.log( user.data ) which returns the user perfectly with all those attributes.

[...next].js

 async authorize(credentials) { const user = await axios.post("http://localhost:4000/api/auth/login", { email: credentials.username, password: credentials.password, }); console.log(user.data); //{ // user: { // id: 1, // name: 'admin', // surname: 'surname admin', // email: 'admin@email.com', // avatar: null, // role: '1', // dob: '2020-01-01T00:00:00.000Z', // description: null, // cv: null, // createdAt: '2022-01-07T00:03:09.000Z', // updatedAt: '2022-01-07T00:03:09.000Z' // } //} // if (user.data.message === "User not found") { return null; } if (user.data.user) { return { id: user.data.user.id, //suppose to be 1 name: user.data.user.name, //suppose to be admin surname: user.data.user.surname, //suppose to be surname email: user.data.user.email, //suppose to be admin@email.com }; } },

index.js

 const { data: session } = useSession(); console.log(session); // OUTPUT: // expires: "2022-02-18T08:55:39.898Z" // id: 1 // user: {name: 'admin', email: 'admin@email.com'}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Try adding something like this inside the NextAuth option

 callbacks: { async session({ session, token }) { session.user = token.user; return session; }, async jwt({ token, user }) { if (user) { token.user = user; } return token; }, },
over 4 years ago · Santiago Trujillo Denunciar

0

Basically you need to pass all the values in the callback and it will work. Pass all token values to session object

 callbacks: { jwt: ({ token, user }) => { if (user) { token.id = user.id; token.name = user.name; token.surname = user.surname; token.email = user.email; } return token; }, session: ({ session, token }) => { if (token) { session.id = token.id; session.name = token.name; session.surname = token.surname; session.email = token.email; } return session; },
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