nextauthjs/next-auth · error · TypeError

redirectProxyUrl must be a valid URL. Received: ${provider.r

Error message

redirectProxyUrl must be a valid URL. Received: ${provider.redirectProxyUrl}

What it means

init validates each provider's redirectProxyUrl by constructing a URL from it; if it is not a parseable absolute URL, a TypeError is thrown. redirectProxyUrl is used to detect whether the current host is acting as a redirect proxy for provider callbacks.

Source

Thrown at packages/core/src/lib/init.ts:82

}: InitParams): Promise<{
  options: InternalOptions
  cookies: cookie.Cookie[]
}> {
  const logger = setLogger(config)
  const { providers, provider } = parseProviders({ url, providerId, config })

  const maxAge = 30 * 24 * 60 * 60 // Sessions expire after 30 days of being idle by default

  let isOnRedirectProxy = false
  if (
    (provider?.type === "oauth" || provider?.type === "oidc") &&
    provider.redirectProxyUrl
  ) {
    try {
      isOnRedirectProxy =
        new URL(provider.redirectProxyUrl).origin === url.origin
    } catch {
      throw new TypeError(
        `redirectProxyUrl must be a valid URL. Received: ${provider.redirectProxyUrl}`
      )
    }
  }

  // User provided options are overridden by other options,
  // except for the options with special handling above
  const options: InternalOptions = {
    debug: false,
    pages: {},
    theme: {
      colorScheme: "auto",
      logo: "",
      brandColor: "",
      buttonText: "",
    },
    // Custom options override defaults
    ...config,

View on GitHub (pinned to a1a16a5a77)

Solutions

  1. Set redirectProxyUrl to a complete absolute URL including scheme and host, e.g. https://example.com/api/auth/callback
  2. Verify the env variable is defined in the deployment environment and referenced with the correct name
  3. Remove redirectProxyUrl entirely if you are not using the redirect proxy feature

Example fix

// before
redirectProxyUrl: process.env.AUTH_REDIRECT_PROXY // undefined -> "undefined"
// after
redirectProxyUrl: process.env.AUTH_REDIRECT_PROXY_URL ?? "https://example.com/api/auth/callback"
Defensive patterns

Strategy: validation

Validate before calling

if (provider.redirectProxyUrl) { try { new URL(provider.redirectProxyUrl) } catch { throw new Error(`redirectProxyUrl must be absolute: got ${JSON.stringify(provider.redirectProxyUrl)}`) } }

Type guard

function isAbsoluteUrl(v: unknown): v is string { if (typeof v !== "string") return false; try { new URL(v); return true; } catch { return false; } }

Try / catch

try { return init(config) } catch (e) { if (e instanceof TypeError && e.message.includes("redirectProxyUrl")) { console.error("Check AUTH_REDIRECT_PROXY_URL is set to an absolute URL"); } throw e; }

Prevention

When it happens

Trigger: Setting provider.redirectProxyUrl (or the top-level redirectProxyUrl passed through to the provider) to a relative path like "/api/auth", an empty string, a value with spaces/typos, or an environment variable that is undefined and interpolated as the literal "undefined".

Common situations: Missing or misnamed env var (e.g. AUTH_REDIRECT_PROXY_URL unset) interpolated into config; using a relative URL instead of an absolute one; deployment-specific base URLs not configured in preview environments.

Related errors


AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28). Data as JSON: /api/errors/30508392c27a770b. Report an issue: GitHub.