Session/User augmentation not working #7033
-
Question 💬Hi, Here's what I have:
Output of authorize is
but output of
is just
How to reproduce ☕️see above Contributing 🙌🏽No, I am afraid I cannot help regarding this |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 4 replies
-
Same here. I've been trying to debug this for hours and hours … |
Beta Was this translation helpful? Give feedback.
-
here's a sample repo illustrating the issue: https://github.com/krinklesaurus/next-auth-test @lluia @balazsorban44 |
Beta Was this translation helpful? Give feedback.
-
In facing same issue, type is not recognised by typescript in server components. However new property appended to session is available in useSession on client components. But it's not available on getServerSession on server components |
Beta Was this translation helpful? Give feedback.
-
This is unrelated to TypeScript. Check out the docs: https://next-auth.js.org/getting-started/example#extensibility |
Beta Was this translation helpful? Give feedback.
-
@balazsorban44 I've been reading the docs for days....could you be more specific please? Just a RTFM is not really helpful 😞 |
Beta Was this translation helpful? Give feedback.
-
I agree with @krinklesaurus. I've read the docs and the issues over here for days, but whenever it's getting close to a solution, it just says RTFM. It's an endless loop. |
Beta Was this translation helpful? Give feedback.
-
Modifying declaration files/types has nothing to do with the runtime values, this is by the nature of TypeScript. I linked to the documentation that explains how you can extend the session via the callbacks, in this case, The following links explicitly explain how to make an There is also https://next-auth.js.org/providers/credentials which I forgot to link, mentioning that the We do not expose Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Thank you. I do have the CredentialsProvider authorize() call in my example though: https://github.com/krinklesaurus/next-auth-test/blob/main/pages/api/auth/%5B...nextauth%5D.js#L19-L30 The CredentialsProvider docs say // Any object returned will be saved in so my assumption was/is that I just need to augment the Session/User type to have my custom properties available but this is not the case. After adding the jwt/session callback, I still dont have the custom properties available in either of the callbacks. Illustrated in this PR: krinklesaurus/next-auth-test#1 The output is just
My understanding is that the user parameter in the callbacks should have my custom properties so I can write them into the jwt/session |
Beta Was this translation helpful? Give feedback.
-
Ok I got it finally working (and I admit I feel a little stupid). In my jwt callback method I had arguments which were wrapped in The callback had the user object under property What confused me here was that the code snippet from the documentation just has
but the docs clearly says
IMO it would be less confusing is the snippet would just have all possible properties, similar to the session callback documentation which lists both user AND token. My proposal would be this v4...krinklesaurus:next-auth:patch-2 Thanks again for helping me out here 😄 |
Beta Was this translation helpful? Give feedback.
-
Commenting because I ran into these exact same compiler errors (using Auth.js, aka next-auth v5 beta), and the fix here did not work for me. What finally did work was realizing that some example / Copilot output I blindly accepted introduced the
Once I did that, suddenly my type augmentation was recognized with no issues. |
Beta Was this translation helpful? Give feedback.
Ok I got it finally working (and I admit I feel a little stupid).
In my jwt callback method I had arguments
https://github.com/krinklesaurus/next-auth-test/blob/bc03bcd5db483bce64a36e26f9208bb0bff2338e/pages/api/auth/%5B...nextauth%5D.js#L14
which were wrapped in
{}
. So a JS object with propertiestoken
,account
, andprofile
. Coming from Java, I naturally expected the 2nd parameter to be the user and just did not see the {}. I thought account is the user but with a different parameter name here. That's the stupid part.The callback had the user object under property
user
though, so I had to change this tohttps://github.com/krinklesaurus/next-auth-test/blob/19614f75fc39d1d7c1d587bdc81f23e…