[GH-ISSUE #598] Cors issues with fasitfy #25656

Closed
opened 2026-04-17 15:54:24 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @lindesvard on GitHub (Nov 19, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/598

Describe the bug
So when I access /auth/ok directly from the browser I get { ok: true } but when using it with fetch from my site I get cors issues. This only occurs from the /auth/* routes.

To Reproduce

// packages/auth/index.ts
export const auth = betterAuth({
  database: prismaAdapter(db, {
    provider: 'postgresql',
  }),
  baseURL: `http://localhost:3333/auth`,
  trustedOrigins: [
    'http://localhost:3000', // website
    'http://localhost:3333', // api
  ],
  emailAndPassword: {
    enabled: true,
  },
});


// apps/api/index.ts
fastify.register(cors, {
  origin: 'http://localhost:3000',
  credentials: true,
});
fastify.all('/auth/*', (req, res) => {
  return toNodeHandler(auth)(req.raw, res.raw);
});

Expected behavior
I except the cors to be respected. Feels like they are overwritten by the lib?

Screenshots
image
image
image

Desktop (please complete the following information):

  • OS: Mac
  • Browser Chrome
Originally created by @lindesvard on GitHub (Nov 19, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/598 **Describe the bug** So when I access `/auth/ok` directly from the browser I get `{ ok: true }` but when using it with fetch from my site I get cors issues. This only occurs from the `/auth/*` routes. **To Reproduce** ``` // packages/auth/index.ts export const auth = betterAuth({ database: prismaAdapter(db, { provider: 'postgresql', }), baseURL: `http://localhost:3333/auth`, trustedOrigins: [ 'http://localhost:3000', // website 'http://localhost:3333', // api ], emailAndPassword: { enabled: true, }, }); // apps/api/index.ts fastify.register(cors, { origin: 'http://localhost:3000', credentials: true, }); fastify.all('/auth/*', (req, res) => { return toNodeHandler(auth)(req.raw, res.raw); }); ``` **Expected behavior** I except the cors to be respected. Feels like they are overwritten by the lib? **Screenshots** ![image](https://github.com/user-attachments/assets/4a1999e9-5c80-4afa-a60a-3b752058debf) ![image](https://github.com/user-attachments/assets/4f9940ef-25cf-460d-91ae-2761fe3fd082) ![image](https://github.com/user-attachments/assets/489e1db5-b3da-48ec-91f7-462dcaca013b) **Desktop (please complete the following information):** - OS: Mac - Browser Chrome
GiteaMirror added the locked label 2026-04-17 15:54:24 -05:00
Author
Owner

@lindesvard commented on GitHub (Nov 19, 2024):

Solved ...

image

<!-- gh-comment-id:2486907370 --> @lindesvard commented on GitHub (Nov 19, 2024): Solved ... ![image](https://github.com/user-attachments/assets/ba74d388-b53e-474d-be88-88795a20b5bb)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25656