mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 00:22:43 -05:00
docs: enhance trustedOrigins option with examples (#3857)
* docs: enhance trustedOrigins option documentation * nit
This commit is contained in:
committed by
GitHub
parent
236c29e270
commit
bb7d504efe
@@ -44,7 +44,11 @@ Default: `/api/auth`
|
||||
|
||||
## `trustedOrigins`
|
||||
|
||||
List of trusted origins.
|
||||
List of trusted origins. You can provide a static array of origins, a function that returns origins dynamically, or use wildcard patterns to match multiple domains.
|
||||
|
||||
### Static Origins
|
||||
|
||||
You can provide a static array of origins:
|
||||
|
||||
```ts
|
||||
import { betterAuth } from "better-auth";
|
||||
@@ -53,6 +57,33 @@ export const auth = betterAuth({
|
||||
})
|
||||
```
|
||||
|
||||
### Dynamic Origins
|
||||
|
||||
You can provide a function that returns origins dynamically:
|
||||
|
||||
```ts
|
||||
export const auth = betterAuth({
|
||||
trustedOrigins: async (request: Request) => {
|
||||
// Return an array of trusted origins based on the request
|
||||
return ["https://dynamic-origin.com"];
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Wildcard Support
|
||||
|
||||
You can use wildcard patterns in trusted origins:
|
||||
|
||||
```ts
|
||||
export const auth = betterAuth({
|
||||
trustedOrigins: [
|
||||
"*.example.com", // Trust all subdomains of example.com
|
||||
"https://*.example.com", // Trust only HTTPS subdomains
|
||||
"http://*.dev.example.com" // Trust HTTP subdomains of dev.example.com
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
## `secret`
|
||||
|
||||
The secret used for encryption, signing, and hashing.
|
||||
|
||||
Reference in New Issue
Block a user