Preview authentication
Preview deployments receive changing hostnames and cannot each have a provider callback registered.
Better Auth · Const
OAuth Proxy lets trusted local and preview deployments use one OAuth client with a fixed production callback URL. It routes their OAuth flows through the production callback server.
oAuthProxy adds a routing layer for OAuth sign-ins from trusted previews and local development. The participating environment sends the flow through the production callback server, which uses the registered production OAuth callback and returns the result to the originating deployment.
oAuthProxy({ productionURL, secret })| Name | Type | Description |
|---|---|---|
productionURL | string | The URL of the production server that receives the provider callback. |
secret | string | A shared dedicated secret used by all trusted participating environments. |
Adds OAuth proxy routing to the Better Auth configuration; the page does not specify a separate return value.
import { betterAuth } from "better-auth"
import { oAuthProxy } from "better-auth/plugins"
export const auth = betterAuth({
plugins: [
oAuthProxy({
productionURL: "https://my-production-app.com",
secret: process.env.OAUTH_PROXY_SECRET,
}),
],
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID || "",
clientSecret: process.env.GITHUB_CLIENT_SECRET || "",
},
},
})Configure the OAuth proxy identically on production and trusted preview or local environments, using one shared secret.
Preview deployments receive changing hostnames and cannot each have a provider callback registered.
A developer needs social sign-in locally without creating a separate OAuth application.
One production OAuth client must serve several trusted environments.
oAuthProxy lets one OAuth client serve local development and preview deployments whose callback URLs are variable. The production server receives the provider callback, exchanges the authorization code, and returns encrypted profile data to the originating deployment.
Follow-up: How is the OAuth provider configured? Register only the production callback URL; the proxy routes preview and development requests through that callback.
Configure the plugin with the production callback server URL and a dedicated secret. Use the same configuration and secret on production, previews, and localhost.
Follow-up: Why must the secret match? The participating environments use it to communicate securely during the proxied flow.
The OAuth provider needs only the callback URL on the production domain. Preview and development callbacks are routed through production automatically by the plugin.
Follow-up: What deployment requirement follows? Only trusted environments should participate, and each must have the plugin installed and the shared secret configured.
betterAuthsocialProviderstrustedOriginsOAuth