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(types): Session callback params does not include user and token #9646

Closed

Conversation

nbifrye
Copy link
Contributor

@nbifrye nbifrye commented Jan 15, 2024

☕️ Reasoning

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

callbacks: {
  session: async ({ session, user }) => {
    if(session.user){
      session.user.id = user.id;
    }
    return session;
  }
},
Property 'user' does not exist on type '({ session: Session; user: AdapterUser; } | { session: Session; token: JWT; }) & { newSession: any; trigger?: "update" | undefined; }'.

This seems to be related to microsoft/TypeScript#14094. Look at this TS Playground example.

type Obj1 = { a: string, b: string }
type Obj2 = { a: string, c: string }

const func = (args: Obj1 | Obj2) => {
    args.b = ""
         ^
         Property 'b' does not exist on type 'Obj1 | Obj2'.
           Property 'b' does not exist on type 'Obj2'.
}

Using { session, user?, token? } instead of { session, user } | { session, token } seems to fix this.

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

Fixes: #9633

📌 Resources

Copy link

vercel bot commented Jan 15, 2024

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

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 0:02am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jan 17, 2024 0:02am

@aakash14goplani
Copy link

Same case with SvelteKitAuth.
image

cc: @ndom91 and @ThangHuuVu

@balazsorban44
Copy link
Member

Closed via #9756. Needs more work in the future. See #9756 (review)

@nbifrye nbifrye deleted the fix/session-callback-args-type branch September 18, 2024 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Refers to `@auth/core` next-auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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