[GH-ISSUE #8478] Dynamic base URL inside database hooks #28425

Open
opened 2026-04-17 19:52:47 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @mmikhan on GitHub (Mar 7, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8478

Is this suited for github?

  • Yes, this is suited for github

There's no way to have access to the dynamic base URL inside a database hook. It is essential to have the dynamic base URL inside database hook to build up the config necessary.

export const auth = betterAuth({
  baseURL: {
    allowedHosts: [
      "myapp.com",
      "www.myapp.com",
      "*.vercel.app",
    ],
  },
  databaseHooks: {
    user: {
      create: {
        after: (user, ctx) => {
          // How do I get access to the baseURL here now? <<<===
          // ctx seems has no baseURL property in it
        }
      }
    }
  }
})

Describe the solution you'd like

Add baseURL to ctx or another prop to the database hooks.

Describe alternatives you've considered

Currently still using the static baseURL rather than using the new dynamic base URL setup. Dynamic base URL is very helpful for monorepo setup.

Additional context

No response

Originally created by @mmikhan on GitHub (Mar 7, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8478 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. There's no way to have access to the dynamic base URL inside a database hook. It is essential to have the dynamic base URL inside database hook to build up the config necessary. ```ts export const auth = betterAuth({ baseURL: { allowedHosts: [ "myapp.com", "www.myapp.com", "*.vercel.app", ], }, databaseHooks: { user: { create: { after: (user, ctx) => { // How do I get access to the baseURL here now? <<<=== // ctx seems has no baseURL property in it } } } } }) ``` ### Describe the solution you'd like Add `baseURL` to `ctx` or another prop to the database hooks. ### Describe alternatives you've considered Currently still using the static baseURL rather than using the new dynamic base URL setup. Dynamic base URL is very helpful for monorepo setup. ### Additional context _No response_
GiteaMirror added the coredatabase labels 2026-04-17 19:52:47 -05:00
Author
Owner

@JacoboGanon commented on GitHub (Mar 8, 2026):

Hello this is actually encompassed by issue #4151, it has been moving slowly but there are some solutions stated there that although aren't ideal will get you out of the problem for the time being.

<!-- gh-comment-id:4018444307 --> @JacoboGanon commented on GitHub (Mar 8, 2026): Hello this is actually encompassed by issue #4151, it has been moving slowly but there are some solutions stated there that although aren't ideal will get you out of the problem for the time being.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#28425