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

fix(ts): show user and token in session callback #9756

Merged

Conversation

ajstars1
Copy link
Contributor

@ajstars1 ajstars1 commented Jan 24, 2024

☕️ Reasoning

In session callback, argument type does not contain user and token

Before code updation 👇

Screenshot 2024-01-24 at 8 34 52 PM

TypeError: Property 'token' does not exist on type '({ session: Session; user: AdapterUser; } | { session: Session; token: JWT; }) & { newSession: any; trigger?: "update" | undefined; }'

Type Intersection: The original code incorrectly used a union type (|), potentially leading to type mismatches. The updated code employs an intersection type (&) to guarantee that both user and token properties are always available within the session callback, regardless of the authentication strategy.

After code updation 👇

Screenshot 2024-01-24 at 8 53 38 PM

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

Fixed: #9633

📌 Resources

Copy link

vercel bot commented Jan 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ❌ Failed (Inspect) Jan 24, 2024 3:32pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2024 3:32pm

Copy link
Member

@balazsorban44 balazsorban44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type Intersection: The original code incorrectly used a union type (|), potentially leading to type mismatches. The updated code employs an intersection type (&) to guarantee that both user and token properties are always available within the session callback, regardless of the authentication strategy.

This is also incorrect since it usually is either user or token, based on the session strategy!

But I think previously we had the same as what this tries to fix, so for backwards compact, we can probably merge this. This needs to be revisited, maybe as part of #9702

Thanks!

@balazsorban44 balazsorban44 changed the title Fixed: Type error in session callback for user and token properties (#9633) fix(ts): show user and token in session callback Jan 24, 2024
@balazsorban44 balazsorban44 merged commit 62f24f5 into nextauthjs:main Jan 24, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Refers to `@auth/core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type error in session callback for user and token properties
2 participants