Update session databaseHook uses Partial<Session> but passes Session to updateWithHook
I'm trying to make use of the updateSession databaseHook but am having issues with the types. Its params are a
Partial<Session>
but the expected return type is a full Session
so even the following usage causes an error:
The issue seems to be here: https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/db/internal-adapter.ts#L412GitHub
better-auth/packages/better-auth/src/db/internal-adapter.ts at main...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
2 Replies
or am I suppose to query the DB and provide the whole session myself? seems wrong given the update function itself is only using the partial correctly
Oh I think I've just misunderstood how the before hooks are supposed to work? Actually it works as I'd expect on user so I do think something is wrong
I think I found the issue I just need to test it: https://github.com/better-auth/better-auth/pull/3396
edit: I've noticed the tests for the databasehooks seem sporadic which is why this wasn't caught. should I just throw one into the adapter tests or add more complex database hook testing?
GitHub
fix: allow partial session data in database hooks by othompson2 · ...
Summary
Fixed session database hooks to accept Partial&lt;Session&gt; instead of requiring complete Session objects
Makes session hooks consistent with user hooks behavior
Resolves issues ...