Skip to content

Looking for clarification on session vs token (and updating) #10938

Answered by k-taro56
AndrewIsh asked this question in Help
Discussion options

You must be logged in to vote

Hi,

Am I correct in using useSession for retrieving data about the user?

Yes!

If so, how can I cause the update I am sending via the update method to be reflected in the session object returned by useSession?

The data passed in the update method is passed to the session argument of the jwt callback.
The token argument of the jwt callback is then passed to the useSession method.
The documentation says to update it like this:

...
export default NextAuth({
  ...
  callbacks: {
    // Using the `...rest` parameter to be able to narrow down the type based on `trigger`
    jwt({ token, trigger, session }) {
      if (trigger === "update" && session?.name) {
        // Note, that `session` c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AndrewIsh
Comment options

Answer selected by AndrewIsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants