How to modify useSession data type?
I am using credentials and providers then returning user, I was trying to put some user infos into session but session.user always returning
37 Replies
id is a field that create-t3-app adds to the session. look in
[nextauth].ts
and next-auth.d.ts
to see how we do it, you can do the same for any other data
that being said be careful with this - only send stuff to the frontend that you're ok with the user seeingI did a lot of changing on that type file
Nothing happened 😄
it should return only id right?
It is returning the same type of object
this is where I log
the interface doesn't determine what is returned
it's just a typedef
types don't exist at runtime
Yes exactly
I couldnt find where I modify returnin object
you already posted it 😉
the session callback
That made me confuse 😄
theres probably a nicer way to write it but this works
I am wondering
"Logged in as" doesn't show a name because it's not being passed anymore
something
where do these come from
?
Do you also know how to do it for the authorize function?
It expects a User object from NextAuth itself or null
But when I override, it overrides only for Session and not User
The error only goes away if I return as
havent used it much tbh
maybe ask next-auth people
we just glue the libraries together 😅
ah okay, thanks haha
@cje do you know where is this come from? sorry for bother you 😄
you mean where the user data comes from?
I am getting the user data from prisma
with credentials
and then returning it
jwt taking the user object
my jwt user object returning me whole user infos but I am using only user id
this is the new session.user object
this is my token object but it doesnt get surname from user object
yea of course not
log token at the start of your jwt function
see what it has
you're adding id to it only in the function
why would it have surname
where are the others comes from? 😄
like
I am giving only id
I am expecting that my token includes only user id
I couldnt understand that where others come from
Options | NextAuth.js
Environment Variables
hmm, thank you very much @cje
in your next-auth.d.ts
as cje said that "the interface doesn't determine what is returned"
I guess the only way to change what jwt includes is decode jwt and update the data and then encode again