How to configure multiple domains? #1053

Closed
opened 2026-03-13 08:20:36 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @Scholar01 on GitHub (Apr 15, 2025).

My website has multiple domain names. When I log in through another domain name, it prompts that the domain name is not verified. How can I add support for multiple domains?

Originally created by @Scholar01 on GitHub (Apr 15, 2025). My website has multiple domain names. When I log in through another domain name, it prompts that the domain name is not verified. How can I add support for multiple domains?
Author
Owner

@seanlucakrueger commented on GitHub (Apr 15, 2025):

Hi,
to protect against CSRF attacks and prevent open redirects, you should explicitly define trusted origins in your auth.ts configuration.

The trustedOrigins option allows you to specify a list of allowed origins. Requests from any origin not included in this list will automatically be blocked.

Example:

trustedOrigins: ["http://localhost:3000", "https://better-auth.com"]

From the documentation:

"Trusted origins prevent CSRF attacks and block open redirects. You can set a list of trusted origins in the trustedOrigins configuration option. Requests from origins not on this list are automatically blocked."

Link:
https://www.better-auth.com/docs/reference/security#trusted-origins

@seanlucakrueger commented on GitHub (Apr 15, 2025): Hi, to protect against CSRF attacks and prevent open redirects, you should explicitly define trusted origins in your `auth.ts` configuration. The trustedOrigins option allows you to specify a list of allowed origins. Requests from any origin not included in this list will automatically be blocked. Example: `trustedOrigins: ["http://localhost:3000", "https://better-auth.com"]` From the documentation: > "Trusted origins prevent CSRF attacks and block open redirects. You can set a list of trusted origins in the `trustedOrigins` configuration option. Requests from origins not on this list are automatically blocked." Link: https://www.better-auth.com/docs/reference/security#trusted-origins
Author
Owner

@dencir commented on GitHub (Apr 15, 2025):

Hi, to protect against CSRF attacks and prevent open redirects, you should explicitly define trusted origins in your auth.ts configuration.

The trustedOrigins option allows you to specify a list of allowed origins. Requests from any origin not included in this list will automatically be blocked.

Example:

trustedOrigins: ["http://localhost:3000", "https://better-auth.com"]

From the documentation:

"Trusted origins prevent CSRF attacks and block open redirects. You can set a list of trusted origins in the trustedOrigins configuration option. Requests from origins not on this list are automatically blocked."

Link: https://www.better-auth.com/docs/reference/security#trusted-origins

What if you have a multi-tenant saas which allows users to link custom domains?

@dencir commented on GitHub (Apr 15, 2025): > Hi, to protect against CSRF attacks and prevent open redirects, you should explicitly define trusted origins in your `auth.ts` configuration. > > The trustedOrigins option allows you to specify a list of allowed origins. Requests from any origin not included in this list will automatically be blocked. > > Example: > > `trustedOrigins: ["http://localhost:3000", "https://better-auth.com"]` > > From the documentation: > > > "Trusted origins prevent CSRF attacks and block open redirects. You can set a list of trusted origins in the `trustedOrigins` configuration option. Requests from origins not on this list are automatically blocked." > > Link: https://www.better-auth.com/docs/reference/security#trusted-origins What if you have a multi-tenant saas which allows users to link custom domains?
Author
Owner

@seanlucakrueger commented on GitHub (Apr 15, 2025):

I think you can technically use:

trustedOrigins: ["*"]

This will allow all origins — but it's not recommended, especially in production, as it weakens the protection against CSRF attacks and open redirects.

If you need more flexibility or dynamic origin handling, you can either check the origin yourself in a custom Middleware or write your own Better Auth plugin to implement advanced origin logic.

But unfortunately I cannot say whether and how it works exactly.

@seanlucakrueger commented on GitHub (Apr 15, 2025): I think you can technically use: `trustedOrigins: ["*"]` This will allow all origins — but it's **not recommended**, especially in production, as it weakens the protection against CSRF attacks and open redirects. If you need more flexibility or dynamic origin handling, you can either check the origin yourself in a custom Middleware or write your own Better Auth plugin to implement advanced origin logic. But unfortunately I cannot say whether and how it works exactly.
Author
Owner

@Scholar01 commented on GitHub (Apr 16, 2025):

Thank you very much for your answer!

@Scholar01 commented on GitHub (Apr 16, 2025): Thank you very much for your answer!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1053