[PR #8455] fix: use fallback URL as initial baseURL for dynamic config #7986

Open
opened 2026-03-13 13:55:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8455
Author: @himself65
Created: 3/6/2026
Status: 🔄 Open

Base: canaryHead: worktree-fix-dynamic-baseurl-8447


📝 Commits (2)

  • 43357aa fix(context): use fallback URL as initial baseURL for dynamic config (#8447)
  • 179387f fix(api): resolve dynamic baseURL in direct auth.api.* calls

📊 Changes

3 files changed (+111 additions, -10 deletions)

View changed files

📝 packages/better-auth/src/api/to-auth-endpoints.ts (+30 -3)
📝 packages/better-auth/src/auth/full.test.ts (+70 -0)
📝 packages/better-auth/src/context/create-context.ts (+11 -7)

📄 Description

Summary

Fixes #8447

  • When using dynamic baseURL config (with allowedHosts), the initial AuthContext.baseURL was set to "" (empty string)
  • While per-request resolution in the handler correctly resolved the baseURL, any code accessing ctx.context.baseURL outside a request context (e.g. auth.api.getOpenIdConfig() or .well-known/openid-configuration) got an empty string, producing broken URLs
  • Now uses the fallback URL (or env vars) to populate the initial baseURL so non-request contexts have a usable value

Test plan

  • Added regression test verifying ctx.baseURL uses the fallback URL when dynamic config is used
  • All existing dynamic baseURL tests pass
  • oauth-provider metadata tests pass
  • pnpm lint, pnpm typecheck pass

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8455 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/6/2026 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `worktree-fix-dynamic-baseurl-8447` --- ### 📝 Commits (2) - [`43357aa`](https://github.com/better-auth/better-auth/commit/43357aaab72cd54c971348b3eae824510e06059a) fix(context): use fallback URL as initial baseURL for dynamic config (#8447) - [`179387f`](https://github.com/better-auth/better-auth/commit/179387fc8a114b08140415e915597bd0c31758fa) fix(api): resolve dynamic baseURL in direct auth.api.* calls ### 📊 Changes **3 files changed** (+111 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+30 -3) 📝 `packages/better-auth/src/auth/full.test.ts` (+70 -0) 📝 `packages/better-auth/src/context/create-context.ts` (+11 -7) </details> ### 📄 Description ## Summary Fixes #8447 - When using dynamic `baseURL` config (with `allowedHosts`), the initial `AuthContext.baseURL` was set to `""` (empty string) - While per-request resolution in the handler correctly resolved the baseURL, any code accessing `ctx.context.baseURL` outside a request context (e.g. `auth.api.getOpenIdConfig()` or `.well-known/openid-configuration`) got an empty string, producing broken URLs - Now uses the `fallback` URL (or env vars) to populate the initial baseURL so non-request contexts have a usable value ## Test plan - [x] Added regression test verifying `ctx.baseURL` uses the fallback URL when dynamic config is used - [x] All existing dynamic baseURL tests pass - [x] oauth-provider metadata tests pass - [x] `pnpm lint`, `pnpm typecheck` pass --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:55:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7986