Feat: fallback NEXT_PUBLIC_AUTH_URL from VERCEL_URL #2420

Closed
opened 2026-03-13 09:52:56 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @tjx666 on GitHub (Nov 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

nextauth support it.

Describe the solution you'd like

What I do in lobe-chat repo:

/**
 * Resolve public auth URL with compatibility fallbacks for NextAuth and Vercel deployments.
 */
const resolvePublicAuthUrl = () => {
  if (process.env.NEXT_PUBLIC_AUTH_URL) return process.env.NEXT_PUBLIC_AUTH_URL;

  if (process.env.NEXTAUTH_URL) {
    try {
      return new URL(process.env.NEXTAUTH_URL).origin;
    } catch {
      // ignore invalid NEXTAUTH_URL
    }
  }

  if (process.env.VERCEL_URL) {
    try {
      const normalizedVercelUrl = process.env.VERCEL_URL.startsWith('http')
        ? process.env.VERCEL_URL
        : `https://${process.env.VERCEL_URL}`;

      return new URL(normalizedVercelUrl).origin;
    } catch {
      // ignore invalid Vercel URL
    }
  }

  return undefined;
};

Describe alternatives you've considered

no

Additional context

No response

Originally created by @tjx666 on GitHub (Nov 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. nextauth support it. ### Describe the solution you'd like What I do in lobe-chat repo: ```ts /** * Resolve public auth URL with compatibility fallbacks for NextAuth and Vercel deployments. */ const resolvePublicAuthUrl = () => { if (process.env.NEXT_PUBLIC_AUTH_URL) return process.env.NEXT_PUBLIC_AUTH_URL; if (process.env.NEXTAUTH_URL) { try { return new URL(process.env.NEXTAUTH_URL).origin; } catch { // ignore invalid NEXTAUTH_URL } } if (process.env.VERCEL_URL) { try { const normalizedVercelUrl = process.env.VERCEL_URL.startsWith('http') ? process.env.VERCEL_URL : `https://${process.env.VERCEL_URL}`; return new URL(normalizedVercelUrl).origin; } catch { // ignore invalid Vercel URL } } return undefined; }; ``` ### Describe alternatives you've considered no ### Additional context _No response_
GiteaMirror added the stalenextjsenhancement labels 2026-03-13 09:52:56 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 29, 2025):

(tag @better-auth-agent if you would like an answer from the Agent)

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 29, 2025): (tag @better-auth-agent if you would like an answer from the Agent) <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Feb 28, 2026):

Hi, @tjx666. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested a feature to add a fallback for NEXT_PUBLIC_AUTH_URL using VERCEL_URL in environment variable resolution.
  • This aims to improve compatibility for NextAuth and Vercel deployments.
  • You referenced your implementation in the lobe-chat repo as a model.
  • The maintainers have not yet provided a direct response.
  • I shared documentation and community resources, but no alternative solutions have been discussed.

Next Steps:

  • Please let us know if this issue is still relevant to the latest version of better-auth by commenting here.
  • If we don’t hear from you within 7 days, this issue will be automatically closed.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 28, 2026): Hi, @tjx666. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested a feature to add a fallback for `NEXT_PUBLIC_AUTH_URL` using `VERCEL_URL` in environment variable resolution. - This aims to improve compatibility for NextAuth and Vercel deployments. - You referenced your implementation in the lobe-chat repo as a model. - The maintainers have not yet provided a direct response. - I shared documentation and community resources, but no alternative solutions have been discussed. **Next Steps:** - Please let us know if this issue is still relevant to the latest version of better-auth by commenting here. - If we don’t hear from you within 7 days, this issue will be automatically closed. Thanks for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2420