Multi-Tenant custom domains
How can I dynamically add my customer's own domains to trusted origins if I want them to be able to configure their own domains like in the Vercel Platforms example?
2 Replies
@Better Auth How can I dynamically add my customer's own domains to trusted origins if I want them to be able to configure their own domains like in the Vercel Platforms example? Is the function based trustedOrigins the way to do it?
Yes, you can achieve this by using a function-based trustedOrigins setup. Instead of providing a static array, you can supply a function that inspects the current request (or uses your internal logic) and returns the valid origins dynamically. This approach is ideal for scenarios like the Vercel Platforms example where customers configure their own domains because it allows you to adjust the list of trusted origins on a per-request basis while still enforcing security [5][17].
Just make sure that any customer-provided domains are properly validated and sanitized before adding them to the trusted list to prevent potential security issues.
Let me know if you have any other questions!
Sources:
[5] Options | Better Auth
[17] docs: enhance trustedOrigins option with examples
Options | Better Auth
Better Auth configuration options reference.
GitHub
docs: enhance trustedOrigins option with examples by Kinfe123 · Pu...
Summary by cubic
Expanded the trustedOrigins documentation with clear examples for static arrays, dynamic functions, and wildcard patterns.