After login in, some of the data returned does not show up on the session, it only returns the email, name. The ID however goes under the user object. Also, I have console.log(user.data) which returns the user perfectly with all those attributes.
[...nextauth].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'}