trustedOrigins is not respected #254

Closed
opened 2026-03-13 07:39:52 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @jakst on GitHub (Nov 20, 2024).

Describe the bug
Adding an origin to trustedOrigins does not have any effect.

import { betterAuth } from "better-auth"
import Database from "better-sqlite3"

export const auth = betterAuth({
  trustedOrigins: ["http://localhost:5173"],
  database: new Database("./sqlite.db"),
})

Requests to sign in from the frontend running at http://localhost:5173 are denied with the following error message.

 ERROR   Invalid origin: http://localhost:5173

ℹ  If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config
 Current list of trustedOrigins: http://localhost:3000

The interesting thing is that the error message adds an extra instance of http://localhost:3000 to the list for each request. So this is what it looks like when doing three requests after each other.

ERROR   Invalid origin: http://localhost:5173

ℹ  If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config
Current list of trustedOrigins: http://localhost:3000

ERROR   Invalid origin: http://localhost:5173

ℹ  If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config
Current list of trustedOrigins: http://localhost:3000,http://localhost:3000

ERROR   Invalid origin: http://localhost:5173

ℹ  If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config
Current list of trustedOrigins: http://localhost:3000,http://localhost:3000,http://localhost:3000

To Reproduce
Steps to reproduce the behavior:

  1. Set up a better-auth server on port 3000. I was following the tutorial for Hono.
  2. Add trustedOrigins: ["http://localhost:5173"] to the config
  3. Set up a frontend on port 5173 and add a signin button that uses the better-auth SDK.
  4. Try to signin
  5. See the error in the auth server logs

Expected behavior
I should be able to trust different origins than the one that the auth server is running on.

Desktop (please complete the following information):

  • OS: MacOS v15.1
  • Browser Chrome
  • Version better-auth v1.0.0-canary.3
Originally created by @jakst on GitHub (Nov 20, 2024). **Describe the bug** Adding an origin to trustedOrigins does not have any effect. ```ts import { betterAuth } from "better-auth" import Database from "better-sqlite3" export const auth = betterAuth({ trustedOrigins: ["http://localhost:5173"], database: new Database("./sqlite.db"), }) ``` Requests to sign in from the frontend running at `http://localhost:5173` are denied with the following error message. ``` ERROR Invalid origin: http://localhost:5173 ℹ If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config Current list of trustedOrigins: http://localhost:3000 ``` The interesting thing is that the error message adds an extra instance of `http://localhost:3000` to the list for each request. So this is what it looks like when doing three requests after each other. ``` ERROR Invalid origin: http://localhost:5173 ℹ If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config Current list of trustedOrigins: http://localhost:3000 ERROR Invalid origin: http://localhost:5173 ℹ If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config Current list of trustedOrigins: http://localhost:3000,http://localhost:3000 ERROR Invalid origin: http://localhost:5173 ℹ If it's a valid URL, please add http://localhost:5173 to trustedOrigins in your auth config Current list of trustedOrigins: http://localhost:3000,http://localhost:3000,http://localhost:3000 ``` **To Reproduce** Steps to reproduce the behavior: 1. Set up a better-auth server on port 3000. I was following the tutorial for Hono. 2. Add `trustedOrigins: ["http://localhost:5173"]` to the config 3. Set up a frontend on port 5173 and add a signin button that uses the better-auth SDK. 4. Try to signin 5. See the error in the auth server logs **Expected behavior** I should be able to trust different origins than the one that the auth server is running on. **Desktop (please complete the following information):** - OS: MacOS v15.1 - Browser Chrome - Version better-auth v1.0.0-canary.3
Author
Owner

@teukuamru commented on GitHub (Nov 20, 2024):

i can confirm this also happens in version 0.8.8

@teukuamru commented on GitHub (Nov 20, 2024): i can confirm this also happens in version 0.8.8
Author
Owner

@jakst commented on GitHub (Nov 20, 2024):

This was fixed in v1.0.0-canary.6.

@jakst commented on GitHub (Nov 20, 2024): This was fixed in `v1.0.0-canary.6`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#254