Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification needed on unstable_update and required adapter methods #11694

Open
adriangalilea opened this issue Aug 28, 2024 · 2 comments
Open
Labels
documentation Relates to documentation triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@adriangalilea
Copy link

adriangalilea commented Aug 28, 2024

What is the improvement or update you wish to see?

I'm trying to use the unstable_update method. And despite appearing on the documentation, it has 0 information on how it's used.

Is there any context that might help us understand?

I tried:

const newSession = await unstable_update({
        user: { username: newUsername },
      });

But it does not update the session.

Since I'm using a custom adapter I thought that the updateSession may be relevant, but after creating it and adding console.log's to it I saw nothing printed on the console, so the unstable_update is not invoking updateSession nor is working by default.

So I'm wondering how is that meant to work.

Does the docs page already exist? Please link to it.

https://authjs.dev/reference/nextjs#unstable_update

@adriangalilea adriangalilea added documentation Relates to documentation triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Aug 28, 2024
@adriangalilea
Copy link
Author

adriangalilea commented Aug 28, 2024

UPDATE: I managed to make it work:

jwt: async ({ token, user, trigger, session }) => {
      if (user) {
        if (!user.id) {
          throw new Error("User ID is required");
        }
        token.user = {
          id: user.id,
          username: user.username,
        };
      }
      if (trigger === "update") {
        token.user = {
          ...token.user,
          username: session.user.username,
        };
      }
      return token;
    },

But I'm guessing it should work without needing this, not sure how.

@agalev
Copy link

agalev commented Sep 24, 2024

UPDATE: I managed to make it work:

jwt: async ({ token, user, trigger, session }) => {
      if (user) {
        if (!user.id) {
          throw new Error("User ID is required");
        }
        token.user = {
          id: user.id,
          username: user.username,
        };
      }
      if (trigger === "update") {
        token.user = {
          ...token.user,
          username: session.user.username,
        };
      }
      return token;
    },

But I'm guessing it should work without needing this, not sure how.

This worked for me. I was able to call unstable_update from a server action and the updated session persists on refresh. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Relates to documentation triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants