Allow additional frontends
A separate frontend, dashboard, or local development server makes authenticated requests to the Better Auth backend.
Better Auth · Pipe
trustedOrigins defines additional origins that Better Auth accepts during request validation. It supports exact origins, wildcard patterns, and dynamic functions, while the app's baseURL is trusted by default.
trustedOrigins extends the default base URL with origins Better Auth accepts during origin validation. It can be a static array, wildcard patterns, or an asynchronous function that computes origins from the request; dynamic functions must also handle initialization calls where the request is undefined.
trustedOrigins: string[] | ((request?: Request) => string[] | Promise<string[]>)| Name | Type | Description |
|---|---|---|
trustedOrigins | string[] | ((request?: Request) => string[] | Promise<string[]>) | A static array of origin strings, wildcard origin patterns, or an asynchronous function returning origins; the function receives a request that may be undefined. |
Not applicable; this is a Better Auth configuration option.
import { betterAuth } from "better-auth";
export const auth = betterAuth({
trustedOrigins: [
"https://app.example.com",
"https://*.example.com",
"http://localhost:3000",
],
});Configure exact origins and an HTTPS wildcard for subdomains in the Better Auth instance.
A separate frontend, dashboard, or local development server makes authenticated requests to the Better Auth backend.
Several subdomains share one authentication service.
Tenants or deployments require origin decisions based on each incoming request.
trustedOrigins is a Better Auth option for adding origins beyond the application's baseURL. It accepts a static list, wildcard patterns, or a function that returns the list.
Follow-up: What must a dynamic provider do during startup? It must handle an undefined request and return default trusted origins.
Better Auth validates request origin information against the configured trusted origins. Origins that are not accepted are rejected, helping defend against CSRF and open redirects.
Follow-up: Why should an origin list be narrow? An overly broad list expands the set of sources accepted by the authentication endpoints.
Wildcard entries match multiple subdomains, and a scheme can constrain the match to HTTP or HTTPS. For example, an HTTPS wildcard can cover HTTPS subdomains of example.com.
Follow-up: What should be checked before using a wildcard? Confirm that the domain and protocol scope do not include unintended applications.
baseURLisTrustedOriginOrigin validationCSRF protectionopen redirects