[GH-ISSUE #6780] A warning should be printed when the user does not provide the baseURL. #10628

Closed
opened 2026-04-13 06:52:18 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @baoziv587 on GitHub (Dec 15, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6780

Is this suited for github?

  • Yes, this is suited for github

I meet an unreasonable baseURL behavior. If I don't define the baseURL, the google provider always defaults to providing a redirectURI starting with http( the hostname for URL is correct), which results in a URI MISMATCH error in the production environment.

One of my services on Kubernetes is bound to two domain names simultaneously. However, when I log in using https://a.com (Google Auth), a redirect link to http://b.com is generated


---

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`a.com`)
      kind: Rule
      services:
        - name: api
          port: 3000  
          
    - match: Host(`b.com`)
      kind: Rule
      services:
        - name: api
          port: 3000            

It took a long time to figure out why the http protocol appeared, and I checked my codebase, Google Cloud, and environment variables everywhere. I hope this can be mentioned in the documentation or a warning log can be written in the console, which will save a lot of time.

 socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID || '',
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            accessType: "offline",
            prompt: "select_account consent",

        },
    },
baseURL: process.env.PROD_URL,

Describe the solution you'd like

console.warn it and mention the possible consequences of undefined behavior in the docs

Describe alternatives you've considered

.

Additional context

No response

Originally created by @baoziv587 on GitHub (Dec 15, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6780 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I meet an unreasonable baseURL behavior. If I don't define the baseURL, the google provider always defaults to providing a redirectURI starting with http( the hostname for URL is correct), which results in a URI MISMATCH error in the production environment. > **One of my services on Kubernetes is bound to two domain names simultaneously. However, when I log in using https://a.com (Google Auth), a redirect link to http://b.com is generated** ```yaml --- apiVersion: traefik.io/v1alpha1 kind: IngressRoute spec: entryPoints: - web routes: - match: Host(`a.com`) kind: Rule services: - name: api port: 3000 - match: Host(`b.com`) kind: Rule services: - name: api port: 3000 ``` It took a long time to figure out why the http protocol appeared, and I checked my codebase, Google Cloud, and environment variables everywhere. I hope this can be mentioned in the documentation or a warning log can be written in the console, which will save a lot of time. ```typescript socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID || '', clientSecret: process.env.GOOGLE_CLIENT_SECRET, accessType: "offline", prompt: "select_account consent", }, }, baseURL: process.env.PROD_URL, ``` ### Describe the solution you'd like console.warn it and mention the possible consequences of undefined behavior in the docs ### Describe alternatives you've considered . ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 06:52:18 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 15, 2025):

Hi @baoziv587! I'm Dosu and I’m helping the better-auth team.

This is a well-supported feature request. There are multiple reports of redirect URI mismatches and confusing behavior when baseURL is not set, especially in multi-domain or proxy setups. The current implementation does not warn or error if baseURL is missing—it just tries to infer it, which can silently cause issues like the one you described. The best place to add a warning is right after baseURL is resolved in the main context initialization, using logger.warn. Here’s a sample warning message that could be added:

if (!baseURL) {
  logger.warn(
    "[better-auth] Warning: No baseURL was provided. Falling back to inferred values may cause incorrect redirect URIs, especially in multi-domain or proxy environments. Set baseURL explicitly or use a dynamic baseURL function for reliable behavior. See the documentation for details."
  );
}

It would also be helpful to add a warning box in the documentation near the baseURL option, explaining that omitting baseURL can lead to redirect URI mismatches and suggesting solutions like setting baseURL explicitly, using a dynamic function, or enabling trustedProxyHeaders for proxy setups. This would save users a lot of debugging time and prevent production issues.

References:

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3656799157 --> @dosubot[bot] commented on GitHub (Dec 15, 2025): <!-- Greeting --> Hi @baoziv587! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a well-supported feature request. There are multiple reports of redirect URI mismatches and confusing behavior when baseURL is not set, especially in multi-domain or proxy setups. The current implementation does not warn or error if baseURL is missing—it just tries to infer it, which can silently cause issues like the one you described. The best place to add a warning is right after baseURL is resolved in the main context initialization, using logger.warn. Here’s a sample warning message that could be added: ```typescript if (!baseURL) { logger.warn( "[better-auth] Warning: No baseURL was provided. Falling back to inferred values may cause incorrect redirect URIs, especially in multi-domain or proxy environments. Set baseURL explicitly or use a dynamic baseURL function for reliable behavior. See the documentation for details." ); } ``` It would also be helpful to add a warning box in the documentation near the baseURL option, explaining that omitting baseURL can lead to redirect URI mismatches and suggesting solutions like setting baseURL explicitly, using a dynamic function, or enabling trustedProxyHeaders for proxy setups. This would save users a lot of debugging time and prevent production issues. References: - [baseURL fallback and lack of warnings in code](https://github.com/better-auth/better-auth/blob/a63e70ea27e2e936ae9915171c0e59054dc9b4a0/packages/better-auth/src/context/create-context.ts#L104-L185) - [getBaseURL fallback logic](https://github.com/better-auth/better-auth/blob/a63e70ea27e2e936ae9915171c0e59054dc9b4a0/packages/better-auth/src/utils/url.ts#L35-L98) - [Community discussion and confusion](https://github.com/better-auth/better-auth/issues/4151) - [User reports of runtime errors and silent failures](https://github.com/better-auth/better-auth/issues/1432) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/5223dc67-083b-4aab-bc21-c2c52723574e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5223dc67-083b-4aab-bc21-c2c52723574e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5223dc67-083b-4aab-bc21-c2c52723574e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5223dc67-083b-4aab-bc21-c2c52723574e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5223dc67-083b-4aab-bc21-c2c52723574e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5223dc67-083b-4aab-bc21-c2c52723574e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5223dc67-083b-4aab-bc21-c2c52723574e?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20well-supported%20feature%20request.%20There%20are%20multiple%20reports%20of%20redirect%20URI%20mismatches%20and%20confusing%20behavior%20when%20baseURL%20is%20not%20set%2C%20especially%20in%20multi-domain%20or%20proxy%20setups.%20The%20current%20implementation%20does%20not%20warn%20or%20error%20if%20baseURL%20is%20missing%E2%80%94it%20just%20tries%20to%20infer%20it%2C%20which%20can%20silently%20cause%20issues%20like%20the%20one%20you%20described.%20The%20best%20place%20to%20add%20a%20warning%20is%20right%20after%20baseURL%20is%20resolved%20in%20the%20main%20context%20initialization%2C%20using%20logger.warn.%20Here%E2%80%99s%20a%20sample%20warning%20message%20that%20could%20be%20added%3A%0A%0A%60%60%60typescript%0Aif%20%28%21baseURL%29%20%7B%0A%20%20logger.warn%28%0A%20%20%20%20%22%5Bbetter-auth%5D%20Warning%3A%20No%20baseURL%20was%20provided.%20Falling%20back%20to%20inferred%20values%20may%20cause%20incorrect%20redirect%20URIs%2C%20especially%20in%20multi-domain%20or%20proxy%20environments.%20Set%20baseURL%20explicitly%20or%20use%20a%20dynamic%20baseURL%20function%20for%20reliable%20behavior.%20See%20the%20documentation%20for%20details.%22%0A%20%20%29%3B%0A%7D%0A%60%60%60%0A%0AIt%20would%20also%20be%20helpful%20to%20add%20a%20warning%20box%20in%20the%20documentation%20near%20the%20baseURL%20option%2C%20explaining%20that%20omitting%20baseURL%20can%20lead%20to%20redirect%20URI%20mismatches%20and%20suggesting%20solutions%20like%20setting%20baseURL%20explicitly%2C%20using%20a%20dynamic%20function%2C%20or%20enabling%20trustedProxyHeaders%20for%20proxy%20setups.%20This%20would%20save%20users%20a%20lot%20of%20debugging%20time%20and%20prevent%20production%20issues.%20%0A%0AReferences%3A%20%20%0A-%20%5BbaseURL%20fallback%20and%20lack%20of%20warnings%20in%20code%5D%28https%3A//github.com/better-auth/better-auth/blob/a63e70ea27e2e936ae9915171c0e59054dc9b4a0/packages/better-auth/src/context/create-context.ts%23L104-L185%29%0A-%20%5BgetBaseURL%20fallback%20logic%5D%28https%3A//github.com/better-auth/better-auth/blob/a63e70ea27e2e936ae9915171c0e59054dc9b4a0/packages/better-auth/src/utils/url.ts%23L35-L98%29%0A-%20%5BCommunity%20discussion%20and%20confusion%5D%28https%3A//github.com/better-auth/better-auth/issues/4151%29%0A-%20%5BUser%20reports%20of%20runtime%20errors%20and%20silent%20failures%5D%28https%3A//github.com/better-auth/better-auth/issues/1432%29)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6780)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10628