Skip to content

fix: fix runtime errors with better-auth 1.4.x API changes#8

Open
Hashibutogarasu wants to merge 1 commit intoyultyyev:mainfrom
Hashibutogarasu:main
Open

fix: fix runtime errors with better-auth 1.4.x API changes#8
Hashibutogarasu wants to merge 1 commit intoyultyyev:mainfrom
Hashibutogarasu:main

Conversation

@Hashibutogarasu
Copy link

@Hashibutogarasu Hashibutogarasu commented Mar 9, 2026

Summary

This PR fixes runtime errors that occur when using the plugin with better-auth 1.4.x.

Changes

Fix createAuthMiddleware import path

createAuthMiddleware was moved from better-auth/plugins to better-auth/api in better-auth 1.4.x. Using the old path causes a runtime module resolution error.

Update internalAdapter API calls to match 1.4.x signatures

Several internalAdapter method signatures changed in better-auth 1.4.x:

Operation Before After
Update user updateUser({ id, ...fields }) updateUser(id, { ...fields })
Create session createSession({ userId, expiresAt }) createSession(userId, undefined, { expiresAt })
Find OAuth user Manual adapter.getAccount() internalAdapter.findOAuthUser()
Link account adapter.upsertAccount / createAccount internalAdapter.linkAccount() / internalAdapter.updateAccount()

Use GenericEndpointContext instead of hand-crafted type

Replaced the local Context type (which used any) with the official GenericEndpointContext type exported from better-auth, improving type safety.

Fix optional chaining on context.path

In better-auth 1.4.18, context.path can be undefined. Added optional chaining (context.path?.startsWith()) with a fallback to prevent runtime crashes in hook matchers.

Testing

  • Verified the plugin works correctly with better-auth 1.4.x
  • All existing tests pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant