Login loads forever on remote access - work when deployed locally and access from localhost #1495

Closed
opened 2026-03-13 08:43:18 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @jpainam on GitHub (Jul 13, 2025).

After hosting my app, the login page shows, but when i click on Login, it loads forever, and there is no logs on the remote server,

I deployed it locally, and it runs well.

export function initAuth() {
  const config = {
    database: prismaAdapter(db, {
      provider: "postgresql",
    }),
    secret: "secret",
    emailAndPassword: {
      enabled: true,
      
    },
   
    plugins: [
      admin(),
      username(),
      apiKey({
        enableMetadata: true,
      }),
      oAuthProxy(),
      expo(),
      nextCookies(),
    ],
  } satisfies BetterAuthOptions;

  return betterAuth(config);
}

I understand i might need trustedOrigins: ["expo://", env.NEXT_PUBLIC_BASE_URL],,
But this didn't work also.
Am I missing something?

Originally created by @jpainam on GitHub (Jul 13, 2025). After hosting my app, the login page shows, but when i click on Login, it loads forever, and there is no logs on the remote server, I deployed it locally, and it runs well. ```ts export function initAuth() { const config = { database: prismaAdapter(db, { provider: "postgresql", }), secret: "secret", emailAndPassword: { enabled: true, }, plugins: [ admin(), username(), apiKey({ enableMetadata: true, }), oAuthProxy(), expo(), nextCookies(), ], } satisfies BetterAuthOptions; return betterAuth(config); } ``` I understand i might need `trustedOrigins: ["expo://", env.NEXT_PUBLIC_BASE_URL],`, But this didn't work also. Am I missing something?
Author
Owner

@dosubot[bot] commented on GitHub (Jul 13, 2025):

This is likely a cross-origin or trustedOrigins config issue. When deployed remotely, if the origin or callback URL isn’t in the trustedOrigins list, Better Auth’s middleware will block the request and throw a FORBIDDEN error, but this may not show up in your logs, causing the client to hang indefinitely (source).

Here’s what to check:

  • Make sure trustedOrigins in your remote config includes every possible frontend origin and scheme you use in production, including wildcards if needed (e.g. "https://yourdomain.com", "expo://*"). For Expo, the scheme in app.json must match what’s in trustedOrigins (docs).
  • If frontend and backend are on different domains, configure CORS on the backend, set credentials: 'include' on frontend requests, and add the frontend domain to trustedOrigins (docs).
  • Double-check that NEXT_PUBLIC_BASE_URL is set correctly in your remote environment and matches the actual deployed frontend URL.
  • In the browser’s network tab, look for failed requests or CORS errors when you try to log in remotely.
  • If you’re using a reverse proxy or custom middleware (like express.json()), make sure it isn’t interfering with request routing before Better Auth handles the request (source).
  • If you’re using an older version of @better-auth/expo, upgrade to 1.2.9+ to avoid cookie expiration bugs (source).

If you try all of the above and it still hangs, try temporarily disabling trustedOrigins (not recommended for production) to confirm if the origin check is the cause.

Let me know what you find in the network tab or if you have more details about your deployment setup!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 13, 2025): <!-- Answer --> This is likely a cross-origin or trustedOrigins config issue. When deployed remotely, if the origin or callback URL isn’t in the trustedOrigins list, Better Auth’s middleware will block the request and throw a FORBIDDEN error, but this may not show up in your logs, causing the client to hang indefinitely ([source](https://github.com/better-auth/better-auth/blob/7835167b8278c88dccbdfdf49ed987efe2811afd/packages/better-auth/src/api/middlewares/origin-check.ts)). Here’s what to check: - Make sure trustedOrigins in your remote config includes every possible frontend origin and scheme you use in production, including wildcards if needed (e.g. `"https://yourdomain.com"`, `"expo://*"`). For Expo, the scheme in app.json must match what’s in trustedOrigins ([docs](https://better-auth.com/docs/integrations/expo)). - If frontend and backend are on different domains, configure CORS on the backend, set credentials: 'include' on frontend requests, and add the frontend domain to trustedOrigins ([docs](https://better-auth.com/docs/concepts/cookies)). - Double-check that NEXT_PUBLIC_BASE_URL is set correctly in your remote environment and matches the actual deployed frontend URL. - In the browser’s network tab, look for failed requests or CORS errors when you try to log in remotely. - If you’re using a reverse proxy or custom middleware (like express.json()), make sure it isn’t interfering with request routing before Better Auth handles the request ([source](https://github.com/better-auth/better-auth/issues/2975)). - If you’re using an older version of @better-auth/expo, upgrade to 1.2.9+ to avoid cookie expiration bugs ([source](https://github.com/better-auth/better-auth/issues/3180)). If you try all of the above and it still hangs, try temporarily disabling trustedOrigins (not recommended for production) to confirm if the origin check is the cause. Let me know what you find in the network tab or if you have more details about your deployment setup! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/4f005cdc-3034-4b66-a958-2361428c6ef9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4f005cdc-3034-4b66-a958-2361428c6ef9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4f005cdc-3034-4b66-a958-2361428c6ef9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4f005cdc-3034-4b66-a958-2361428c6ef9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4f005cdc-3034-4b66-a958-2361428c6ef9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4f005cdc-3034-4b66-a958-2361428c6ef9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4f005cdc-3034-4b66-a958-2361428c6ef9?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3362)
Author
Owner

@jpainam commented on GitHub (Jul 13, 2025):

The redirect from nextjs was causing a status code 303

@jpainam commented on GitHub (Jul 13, 2025): The `redirect` from nextjs was causing a `status code 303`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1495