-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Environment
npmPackages:
@auth/core: ^0.* => 0.20.0
@auth/drizzle-adapter: ^0.* => 0.3.14
@auth/sveltekit: ^0.* => 0.5.2
Node: 20.3.1 - /opt/homebrew/bin/node
Reproduction URL
https://github.com/thomasmol/authjsbugs
Describe the issue
related to #9437
i get a type error in the session callback for the user
or token
property:
Property 'user' does not exist on type '({ session: Session; user: AdapterUser; } | { session: Session; token: JWT; }) & { newSession: any; trigger?: "update" | undefined; }'.
error claims user
does not exist, while it does, although it depends on the database strategy used.
error located here on the user
property in hooks.server.ts
:
callbacks: {
session: async ({ session, user }) => {
if(session.user){
session.user.id = user.id;
}
return session;
}
},
not sure if useful but this is copilot explaining:
"The error message you're seeing is due to TypeScript not being able to determine the exact type of the object that's being passed to the session callback. The type of the object is a union type, which means it could be one of several types. In this case, it could be { session: Session; user: AdapterUser; } or { session: Session; token: JWT; }.
The user property exists on the first type, but not on the second. When you try to access user.id, TypeScript can't guarantee that user will always be present, hence the error."
How to reproduce
install auth core + auth sveltekit, create hooks.server.ts and add a the session callback. type error occurs on user and token, but not the session property.
Expected behavior
no type errors