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:

databaseHooks: {
  session: {
    update: {
      before: async (session) => {
        return {
          data: session,
        };
      },
    },
  },
},


Type 'Partial<{ id: string; token: string; userId: string; expiresAt: Date; createdAt: Date; updatedAt: Date; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }>' is not assignable to type '{ id: string; token: string; userId: string; expiresAt: Date; createdAt: Date; updatedAt: Date; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }'.
              Types of property 'id' are incompatible.
                Type 'string | undefined' is not assignable to type 'string'.
                  Type 'undefined' is not assignable to type 'string'.ts(2322)


The issue seems to be here: https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/db/internal-adapter.ts#L412
GitHub
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Was this page helpful?