I’m using firebase auth provider (email/password) option with next-auth v4 in my next.js project. What I want to do is access the JWT token from the session on my client using the useSession() hook. this is my authorize function:
CredentialsProvider({
name: 'Credentials',
credentials: {
email: { label: "Email", type: "text", placeholder: "[email protected]" },
password: { label: "Password", type: "password", placeholder: "*******" }
},
async authorize(credentials, req) {
console.log("attempting to authorize creds");
try {
const userCredential = await signInWithEmailAndPassword(
auth,
credentials?.email as string,
credentials?.password as string,
);
console.log(userCredential.user.uid);
const token = await userCredential.user.getIdToken();
console.log(token);
const user: MyUser = {
id: userCredential.user.uid,
email: userCredential.user.email,
token: token
};
const sendUser = { id: userCredential.user.uid, ...userCredential.user, token: token }
return sendUser;
} catch (error) {
console.log("Invalid credentials.")
return null;
}
}
})
But upon doing this, I am only getting the email field and not the id and token. I verified this by adding the token in the email field and indeed I was getting the token in the email field but there was no token or id field. I should’ve gotten something like
{
"id" : 1234,
"email:"[email protected]",
"token": "ASDasdasFMASFasf123ad"
}
however, I only get this:
{
"email:"[email protected]"
}