refactor: encode auth external url explicitly#5092
Open
Conversation
Coverage Report for CI Build 24723674117Coverage decreased (-0.02%) to 63.667%Details
Uncovered Changes
Coverage Regressions5 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR simplifies how the CLI wires Supabase Auth / GoTrue URLs in local development so the values we pass match what upstream
supabase/authactually expects.Before this change, the CLI passed the bare API external URL as
API_EXTERNAL_URL, then separately prebuilt auth-specific URLs in several places by appending/auth/v1,/verify, and/callback. Upstream Auth already knows how to derive those paths from its external URL, so this created duplicated logic in the CLI and made the setup easier to misconfigure.This PR introduces a single canonical auth external URL, uses it consistently for GoTrue, and stops precomputing auth callback / mailer URLs that Auth can derive on its own.
What changed
1. Added
auth.external_urlA new optional config field was added:
Its purpose is to represent the public URL that Auth serves on, including the
/auth/v1prefix in the local stack.Behavior:
auth.external_urlis unset, it now defaults toapi.external_url + "/auth/v1".auth.external_urlis explicitly set, that value is preserved as-is.auth.jwt_issuerstill remains a separate explicit override and is preserved as-is when set.2. GoTrue now receives the auth-scoped external URL
The CLI now passes:
API_EXTERNAL_URL=<auth external url>GOTRUE_JWT_ISSUER=<auth.jwt_issuer>instead of using the bare API external URL for
API_EXTERNAL_URL.This matches upstream
supabase/authbehavior more closely, where:API_EXTERNAL_URLis the public base URL GoTrue thinks it lives atAPI_EXTERNAL_URL + "/callback"API_EXTERNAL_URLplus configured relative pathsAPI_EXTERNAL_URLThis change was applied both to the long-running GoTrue container and the auth migration job so the behavior stays consistent.
3. Stopped prebuilding mailer URLs in the CLI
The CLI no longer sends fully-qualified mailer paths like:
<jwt_issuer>/verifyInstead, it now sends the relative values GoTrue expects:
/verifyfor:
GOTRUE_MAILER_URLPATHS_INVITEGOTRUE_MAILER_URLPATHS_CONFIRMATIONGOTRUE_MAILER_URLPATHS_RECOVERYGOTRUE_MAILER_URLPATHS_EMAIL_CHANGEThis lets Auth resolve them against its own external URL instead of the CLI building those URLs itself.
4. Provider redirect overrides are now opt-in only
For built-in external providers, the CLI used to always send
GOTRUE_EXTERNAL_<PROVIDER>_REDIRECT_URI, defaulting it to<jwt_issuer>/callbackwhenredirect_uriwas empty.Now:
[auth.external.<provider>].redirect_uriis explicitly set, the CLI passes it through unchangedAPI_EXTERNAL_URLThis keeps explicit user overrides working while removing duplicated default callback logic from the CLI.
5. Updated docs/comments
auth.external_urlto the generated config templatejwt_issuercomment to reflect the new defaulting behaviorredirect_uricomment for providers/auth/v1/*/verify,/callback,/authorizeWhy this helps
This reduces duplicated URL construction logic in the CLI and aligns the local stack with upstream Auth’s contract.
Benefits:
/auth/v1,/verify, and/callback/auth/v1/auth/v1auth.external_url)auth.jwt_issuer)redirect_uri)supabase/authis designed to workCompatibility / behavior notes
This PR preserves existing explicit overrides:
auth.jwt_issueris still authoritative when set[auth.external.<provider>].redirect_uriis still authoritative when seturloverrides are unchangedThis PR does not remove Kong path stripping. That remains necessary because upstream Auth still serves routes at root paths like
/verify,/callback, and/authorize, rather than under a configurable base path such as/auth/v1.