Skip to content
FirstUser

For builders shipping this week

Replit app login works in Preview but not after publishing? 5 checks

Check it like a stranger would. FirstUser opens your published Replit URL in a fresh browser, signs up with a new email and password, opens the confirmation link when the test inbox has one, logs in and tries checkout. It does not read or type a verification code. Every failed step comes with a screenshot and a fix prompt you can paste into Replit Agent. Run a free signup test.

Sign-in works in the Replit Preview. You publish, open the .replit.app address or your own domain, and login fails, loops, or your account "doesn't exist". That is rarely a bug in the login code. Replit's docs say the published app gets its own database, its own secrets and its own address, and with Clerk Auth its own user store. The Preview runs while you are signed in to Replit, and development URLs require authentication. Your users have none of that.

Work through these five checks in order. Each one names the place in Replit where you look.

1. Can a stranger open the app at all?

Before blaming login, check who is allowed in.

  • Access setting. When you publish, the Sharing selector offers Public, Password protected, Workspace only and Invite only. With the two private options, Replit's docs say visitors without access "are prompted to sign in through Replit before they can view the app". Apps in an organization workspace default to a private option. To a new user that looks exactly like a broken login. Changing access requires unpublishing, choosing a different option under Sharing, and publishing again.
  • You shared the wrong link. Development URLs (replit.dev) are private by default and require authentication. Replit says sharing the URL alone "does not grant access". Send people the published address.
  • Static deployment. Replit's publishing guide says apps with API routes, authentication callbacks or server-side database calls "may not be a good candidate for Static Deployments" and points to Autoscale. A login that needs a server callback has nothing to call on a static site. Secrets are not available to Static Deployments.

2. Which auth system, and which environment are you looking at?

Ask Replit Agent first: "Does this app use Replit Auth, Replit-managed Clerk Auth, or a separately configured authentication provider?" That is the first step in Replit's auth troubleshooting guide. The answer changes everything below.

  • Clerk Auth (the default Agent picks on Starter, Core and Pro): every app gets a Development and a Production environment with separate user stores. Replit's docs: "An account you create on the dev/preview app exists only in the Development environment and is not copied to Production when you publish — you'll need to sign up again on the published app." The same holds for data you keyed to a Clerk userId. In the Auth pane, use the environment toggle on the Users tab to see who exists in Production.
  • Replit Auth (the Enterprise default): your users sign in with a Replit account on a Replit-branded page. Replit says it works across replit.dev, replit.app and custom domains.
  • Your own provider (Supabase, Firebase, your own Clerk account and so on): check that provider's settings as well as the app. Do not mix configuration from a Replit-managed Clerk tenant and your own Clerk account.

Two more things that make a working login look broken:

  • The database is different. Every Replit app has a development database and a production database, and both use a variable called DATABASE_URL with a different value. Users you created while testing live in development. Replit's docs warn that development data can include test accounts, so don't fix this by copying it into production; sign up again on the live app.
  • Triggers don't travel. Publishing applies table changes with drizzle-kit, but it does not copy functions, procedures, triggers or grants. Replit's example is a trigger that updates a timestamp: publishing succeeds, and the trigger does not run in production. The same gap hits a trigger that creates a profile row on signup. It runs in Preview and not on the published app. Replit's database troubleshooting page has SQL to list what exists only in development.

3. Are the production secrets there?

Replit's publishing guide says: "Secrets you set in the Project Editor do not automatically carry over to your published app." Missing secrets "can cause errors about undefined values, failed API calls, database connection failures, login errors, or payment failures."

  • Open Publishing → Adjust settings → Production app secrets and compare it with the Secrets tool: session secret, OAuth client ID and secret, any auth or API keys the server reads.
  • Publish again after a change. Replit's auth troubleshooting says to publish the configuration, then test in a fresh browser session.
  • With Replit-managed Clerk, don't paste live keys into the Secrets pane. The workspace keeps pk_test/sk_test and the published app runs with pk_live/sk_live automatically. Replit says replacing the test keys "will break the automatic dev/production switch". You can check the prefixes under Publishing → Overview → Adjust settings.
  • If checkout also breaks after publishing: with your own Stripe keys, Replit's Stripe guide puts the live keys in Production app secrets, registers a separate live-mode webhook endpoint on the published URL, and sets STRIPE_WEBHOOK_SECRET to that endpoint's signing secret, "not the CLI listener's secret", then publish or republish. More on a paid-but-still-free plan: Paid in Stripe, but the plan is still free.

4. Does every callback and allow list know the published address?

The Preview runs on a replit.dev address. The published app runs on .replit.app or your domain.

  • Don't build URLs from REPLIT_DEV_DOMAIN. Replit sets it to the development URL, "which is different from the Deployment URL". A callback built from it points users back to the dev address. REPLIT_DOMAINS lists all domains of the project, and REPLIT_DEPLOYMENT is 1 only in the published app.
  • Own OAuth provider: compare its allowed origins and callback URLs with "the exact published hostname and protocol" (Replit's words). For redirect_uri_mismatch, compare the URI actually sent with the registered one. Replit advises not to guess a callback path or add a wildcard.
  • New custom domain: with Replit Auth, "Republish to refresh the domain list (REPLIT_DOMAINS environment variable)". With Clerk and your own OAuth credentials, a domain change can change callback URLs and JavaScript origins. The Configure tab shows warning icons where setup steps are left. Test the default .replit.app address first: if only the custom domain fails, it is a domain problem.
  • www is a separate domain. Linking the apex domain does not serve www. If users reach both, add both and redirect one to the other. A session is stored for one host, so it does not follow to the other.
  • Supabase as the backend: the Site URL and Redirect URLs must name the published address. See password reset or magic link opens localhost and Google login not working on the live site.

You don't need a CNAME record for login on a custom domain. Replit says those records are for email sending, such as Clerk's verification codes, not sign-in.

5. Does the session cookie survive?

If login "succeeds" and the next page shows you logged out again, the server didn't get its session back.

  • Express with express-session and cookie: { secure: true }: the express-session README says a secure cookie is not set when the browser reaches the site over plain HTTP, and "if you have your node.js behind a proxy and are using secure: true, you need to set 'trust proxy' in express" (app.set('trust proxy', 1)). Ask Agent whether your server sets it.
  • Session secret: if the server signs sessions with SESSION_SECRET, it has to be in Production app secrets (check 3).
  • Supabase in the browser and a server that checks cookies: that mismatch causes a login loop of its own. See "Auth session missing!" or a login loop after deploy.
  • Test outside the editor. Replit's Preview docs send you to a new browser tab for network requests and browser storage. Replit's auth troubleshooting says to test in a fresh browser session. Use a private window on the published address, where you aren't signed in to Replit.

The 2-minute test

  1. Open the published URL (not replit.dev) in a private window.
  2. Sign up with an email you have never used on this app.
  3. Confirm the email if asked, then log in.
  4. Reload, open a deep link in a new tab, log out and log in again.
  5. If there is a paid plan, start checkout and come back from it still signed in.

If any step fails, open the Logs tab in the Publishing pane at the same minute and paste the error into Agent. The same five checks show up on other hosts: login works on localhost but not on Vercel and Bolt signup works in the preview but fails on Netlify.

FAQ

Why can't I log in to my published app with the account I made in Preview?

With Clerk Auth, Development and Production have separate user stores, and an account created on the dev/preview app is not copied when you publish. With your own auth tables, the published app reads the production database. Sign up again on the published app.

Do I have to republish after changing a secret?

Yes. Production app secrets are separate from the Secrets tool. Publish the change, then test in a fresh browser session. Replit's Stripe guide says to publish or republish after you set the live webhook secret.

Login works on .replit.app but not on my domain.

Republish so the domain list is refreshed, add the domain (and www if you use it) to every callback and origin list, and recheck Clerk's Configure tab if you use your own OAuth credentials.

Can FirstUser catch this?

FirstUser opens your published URL in a fresh browser, looks for a sign-up link and an email field, and signs up with a new email and password. It opens a confirmation link from the test inbox when one arrives. It does not read or type a verification code. Replit-managed Clerk sends a verification code, not a link. When the page asks for email confirmation and no link arrives, the confirm step fails with "The app asked for email confirmation, but no confirmation link arrived." When the page does not ask, the confirm step is skipped with "The page did not ask the test user to confirm an email." and login is still tried. If no sign-up form is found, the step fails with "No sign-up form was found." If the app never shows a signed-in state, it fails with "Login was submitted, but the app did not show a signed-in state." Each failed step comes with a screenshot and a fix prompt for Replit Agent. It does not read your Replit logs or secrets. Apps that only offer "Sign in with Replit" or social buttons have no email form for it to fill. See also Test a Replit app signup. Run a free signup test.

One fix like this per email

A short tip each day for Lovable, Bolt and Cursor apps. Unsubscribe anytime.

We'll email that address. Privacy policy

Sources