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

Docs: Bug in code example #11682

Closed
Jay-Karia opened this issue Aug 27, 2024 · 5 comments · Fixed by #11912
Closed

Docs: Bug in code example #11682

Jay-Karia opened this issue Aug 27, 2024 · 5 comments · Fixed by #11912
Labels
docs Relates to documentation good first issue Good issue to take for first time contributors

Comments

@Jay-Karia
Copy link
Contributor

What is the improvement or update you wish to see?

The code examples listed here: https://authjs.dev/guides/extending-the-session#with-jwt
as a Typescript error.

code_bug

Is there any context that might help us understand?

The code should be updated to:

 callbacks: {
    jwt({ token, user }) {
      if (user) {
        token.id = user.id;
      }
      return token;
    },
    session({ session, token }) {
      if (session.user) {
        session.user.id = token.id as string; // add "as string"
      }
      return session;
    },
  },

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

https://authjs.dev/guides/extending-the-session#with-jwt

@Jay-Karia Jay-Karia added docs Relates to documentation triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Aug 27, 2024
@halvaradop
Copy link
Contributor

To remove these errors and enable autocompletion for the properties, you need to extend the JWT type in your project. For more information on how to do this, read more here. The default values for these types are:

interface JWT  {
  name?: string | null
  email?: string | null
  picture?: string | null
  sub?: string
  iat?: number
  exp?: number
  jti?: string
}

For this reason, the id property is unknown and shows as not assignable to type string.

@Jay-Karia
Copy link
Contributor Author

IMO, this should be mentioned in the docs

@balazsorban44 balazsorban44 added good first issue Good issue to take for first time contributors and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Sep 25, 2024
Copy link

This issue was marked with the good first issue label by a maintainer.

This means that it is a good candidate for someone interested in contributing to the project, but does not know where to start.

Have a look at the Contributing Guide first.

This will help you set up your development environment to get started. When you are ready, open a PR, and link back to this issue in the form of adding Fixes #1234 to the PR description, where 1234 is the issue number. This will auto-close the issue when the PR gets merged, making it easier for us to keep track of what has been fixed.

Please make sure that - if applicable - you add tests for the changes you make.

If you have any questions, feel free to ask in the comments below or the PR. Generally, you don't need to @mention anyone directly, as we will get notified anyway and will respond as soon as we can)

Note

There is no need to ask for permission "can I work on this?" Please, go ahead if there is no linked PR 🙂

@balazsorban44
Copy link
Member

Simply linking to https://authjs.dev/getting-started/typescript should be sufficient

@halvaradop
Copy link
Contributor

Currently, there is a link that navigates to the TypeScript docs, or your idea would be to add a link in the base description ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Relates to documentation good first issue Good issue to take for first time contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@balazsorban44 @Jay-Karia @halvaradop and others