I'm creating an application in next.js and using the next-auth package for the login access process.
I'm trying to add a new "apiToken" key that I get from my api, to the session cookie created by next-auth after performing an oauth login.
I'm doing it as follows: in the "signIn" callback I'm creating "user.apiToken" and passing the token I get from my api, in the "jwt" callback I try to create "token.apiToken" and pass the value of "user.apiToken" so that it can retrieve this value in the "session" callback and thus write this value to the session cookie.
The problem is that for some reason I don't know, the application goes through the "jwt" callback twice, the first time I have all the user values, but the second time user comes with an undefined value, giving me an error in the application.
Has anyone gone through this problem? Or could you help me with a solution?