All posts

Users keep getting logged out of your app? Causes and fixes

"I keep getting logged out." "It logged me out on my iPhone." "I have to sign in again every day." If you built your app with Lovable, Bolt, Cursor or Replit, or by hand with Vite, React or Vue, on Supabase Auth or Firebase Auth, you have probably heard one of these. Vendor facts below come from the official docs, checked in November 2026.

Short answer: I would check these in this order. First, whether a session setting ends logins on purpose: a time limit, an inactivity timeout or one session per user. Second, whether the user is on Safari or an iPhone and the session sits in localStorage. Third, whether the user is on a different domain (www, a preview URL) than the one they signed in on. Fourth, whether the app creates more than one auth client or refreshes in several tabs. Fifth, whether your own code calls sign out when something fails. Then look at the logs.

1. How a login stays alive

A login is not one thing that lasts. It is two tokens. A short-lived access token proves who the user is. A refresh token gets a new access token when the old one runs out. The app does this in the background, so the user never sees it.

Supabase describes it in its sessions guide: access tokens are "designed to be short lived" while refresh tokens "never expire but can only be used once." For the access token lifetime, the same page says "Most applications should use the default expiration time of 1 hour." The page lists what ends a session, "depending on configuration":

  • "The user clicks sign out."
  • "The user changes their password or performs a security sensitive action."
  • "It times out due to inactivity."
  • "It reaches its maximum lifetime."
  • "A user signs in on another device."

Firebase works in a similar way. Its session management page says "Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens." It also says "Refresh tokens expire only when one of the following occurs": the user is deleted, the user is disabled, or "A major account change is detected for the user." That includes "password or email address updates." So if only a few users complain, ask whether they just changed their password or email.

If you want the security side of sessions, such as how long people should stay logged in, that is in the login hardening post. This post is about the opposite problem: logouts nobody wanted.

2. Cause: session settings that end logins on purpose

Supabase can end sessions on purpose. The sessions guide lists "Time-boxed sessions, which terminate after a fixed amount of time" and an inactivity timeout, which "terminates sessions that haven't been refreshed within the timeout duration." Both are options in the project's Auth settings. The page notes "This feature is only available on Pro Plans and up", so check your plan before you count on these settings, and check what is set if you did not set them yourself. The page also says that "the actual duration of a session is the configured timeout plus the JWT expiration time", so a user may be logged out later than the number you typed.

One more setting causes the classic "it logs me out on my laptop when I use my phone" complaint. Under the same Pro-plan section, Supabase offers "Single session per user". The guide says: "When this is enabled, the session from the most recent sign in will remain active, while the rest are terminated." It also notes that "the effect will only be noticed at intervals of the JWT expiration time", so the other device seems to log out at a random moment, up to an hour later. If users switch between devices, check this setting first.

The Firebase page I read does not describe a setting like this, so I leave Firebase out here. If someone is logged out on Firebase, look at the other causes.

3. Cause: Safari and iPhone storage rules

This is the one behind "it only happens on iPhone". Browser-only apps usually keep the session in the browser's own storage, such as localStorage. WebKit, the engine behind Safari, limits that. In its post Full Third-Party Cookie Blocking and More (March 2020), WebKit says Intelligent Tracking Prevention is "deleting all of a website's script-writable storage after seven days of Safari use without user interaction on the site." The list of affected storage includes IndexedDB, LocalStorage, SessionStorage and "Service Worker registrations and cache."

What that means for your app, as I read it: if the session lives in localStorage and a user has not interacted with your site during seven days of Safari use, the session can be gone and they have to sign in again. This applies to Safari and WebKit as WebKit describes it. I would not assume it explains logouts in Chrome or Firefox.

WebKit also has a note for apps added to the Home Screen: "Web applications added to the home screen are not part of Safari and thus have their own counter of days of use." And: "We do not expect the first-party in such a web application to have its website data deleted." So a user who opens your site in a Safari tab and a user who opens it from the Home Screen can have different experiences. If you are choosing between a web app and a store app, see installable web app or App Store.

If your app is rendered on a server, cookies are another option. Supabase's server-side rendering guide says to configure the client "to store the user session in cookies instead of local storage." Test any change on a real iPhone.

4. Cause: www, non-www and preview domains

Browser storage belongs to one origin. MDN says localStorage gives access to "a Storage object for the Document's origin", and its same-origin policy page says "Two URLs have the same origin if the protocol, port (if specified), and host are the same for both."

So example.com and www.example.com are two different places. A user who signs in on one is logged out on the other. The same goes for a Netlify or Vercel preview URL, or the default .lovable.app address next to your own domain.

The fix is one canonical domain, with a redirect from every other address to it. The setup is in connecting your own domain. Also check that your sign-in redirect URLs point at that one domain. Social sign-in adds its own traps: what breaks with Google and Apple sign-in.

5. Cause: two tabs or two auth clients

Supabase explains the exceptions in its sessions guide: "A refresh token can be used more than once within a defined reuse interval. By default this is 10 seconds and we do not recommend changing this value." It lists "bugs or issues with serializing access to the refresh token request" as one reason for the leeway. And then: "Should the reuse attempt not fall under these two exceptions, the whole session is regarded as terminated and all refresh tokens belonging to it are marked as revoked."

The docs do not say outright that two clients or two tabs cause this. So treat it as something to check, not a fact. What I would check: does the code create the Supabase client in more than one place? Supabase says that for its server-side package, "createBrowserClient already uses a singleton pattern" (from the creating a client guide), but AI-generated code often has a second client in some helper file. Then open the app in two tabs, leave both for over an hour, and see if one of them logs out.

6. Cause: your own code signs the user out

This one is common in generated code. Look for a sign out call inside an error handler: a failed API call, a 401 from your own backend, a network error while offline. One bad request then ends a good session. Also look for code that clears localStorage or the whole storage on startup or after a deploy, and for a redirect to the login page that runs before the session has been loaded.

A stale build after a deploy can also look like a logout, because old files talk to a changed backend. If things break only after you publish, read why an app works in the editor and breaks live. If buttons stop doing anything right after a deploy, see buttons that stop working after a deploy.

7. How to diagnose it

  1. Ask the user four things: which device, which browser, how long since their last visit, and which address they type or tap.
  2. Look at the Auth logs. In the Supabase dashboard, the logs guide says you can pick Auth as the log type, and the User filter will "Match the user's ID in Auth actor IDs or API Gateway JWT subjects."
  3. Reproduce it in two tabs, and again in Safari on a Mac or an iPhone.
  4. Open DevTools, Application tab. Look under Local Storage and Cookies for your domain. Is the session stored there? Is it still there after you reload? Check you are on the same domain the user is.
  5. Search your code for every sign out call and every place a client is created.

8. Prompts for your AI tool

  1. "Find every place in this app that calls signOut, clears localStorage or sessionStorage, or redirects to the login page. For each one, tell me why it runs and what triggers it. Do not change anything yet."
  2. "Check that the app creates exactly one Supabase (or Firebase) auth client, in one shared file, and that every other file imports it. Remove any extra clients."
  3. "Pick example.com as the only canonical domain. Add a permanent redirect from www and from any other address to it, and make sure the sign-in redirect URLs use only that domain."

9. Checklist

  • Session time limits and inactivity timeout checked in the Auth settings, and your plan confirmed.
  • Single session per user checked, if users work on more than one device.
  • You know where the session lives on iPhone Safari, and what WebKit's seven-day rule does to it.
  • One canonical domain, with a redirect from www and previews.
  • One auth client in the code.
  • Tested with two tabs open for over an hour.
  • No sign out call inside generic error handlers.
  • No code that clears storage on start or deploy.
  • Auth logs checked for a user who was logged out.

Want this fixed for you?

I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including login and session problems like these. Or send me the details and I'll reply within 24 hours.