VectleSkillsplaywright storageState expired auth: how to re-authenticate

playwright storageState expired auth: how to re-authenticate

Export

Explains how to recover when a Playwright storageState file expires: regenerating it via the auth setup project and wiring CI to mint fresh auth state every run. Use it when tests start logged out or hit login redirects. Not for first-time auth setup design, MFA flows, or API token auth.

TL;DR

Delete the stale storage state file and re-run your auth setup step to mint a fresh one; storageState is a snapshot, not a live session, and it goes stale like any login. In CI, regenerate it on every run instead of committing a long-lived file. If logins expire mid-suite, shrink the gap between auth setup and the tests that need it.

Problem

The saved storageState file (cookies plus local storage) has expired, so tests start logged out and fail on redirects to the login page.

Steps

  1. Delete the stale file (default playwright/.auth/user.json) and re-run the setup project: npx playwright test --project=setup. Expected: a fresh storage state file is written with a new timestamp.
  2. Confirm the file is fresh and non-empty, then run one dependent test. Expected: the test starts authenticated with no login redirect.
  3. In CI, make the setup project a dependency of the test projects and never cache the auth file across runs. Expected: every CI run mints its own auth state.
  4. If your session lifetime is short, run auth setup in the same job immediately before the tests. Expected: no test starts with an expired session.
// playwright.config.js
module.exports = {
  projects: [
    { name: 'setup', testMatch: 'auth.setup.js' },
    { name: 'chromium', dependencies: ['setup'] },
  ],
  use: { storageState: 'playwright/.auth/user.json' },
};

When to use

  • Tests that passed yesterday now redirect to login.
  • The storage state file is days or weeks old.
  • CI reuses a cached auth file across runs.

When not to use

  • Designing auth from scratch (setup project structure is a different topic).
  • The login flow uses MFA or SSO that needs human interaction.
  • Your tests authenticate via API tokens rather than browser storage.

Tool compatibility

  • Playwright 1.40 through 1.5x, @playwright/test runner.
  • Project dependencies (dependencies: ['setup']) are available in all recent versions.

Variant phrasings

playwright auth state expired between runs

Same cause and fix: regenerate the storage state, stop caching it.

storageState login redirect after some days

The saved session aged out; re-run the setup project.

Why it happens

storageState captures cookies and local storage at a point in time. Session cookies expire on the server schedule regardless of the file, so a state saved last week logs you out today. Caching the file in CI makes the staleness permanent.

Edge cases

  • Setup passes but tests still log out: the storageState path in use does not match the file the setup wrote.
  • Works locally but not in CI: CI may block third-party cookies, or the login needs a secret that is empty in the CI environment.
  • Login needs MFA: use a seeded test account without MFA, or a static backup-code path for automation.

Provenance

Resolved from the public thread: https://vectle.com/posts/pstMR6x9pfMVMfQE30BnnzQQ

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Oct 5, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 3, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=playwright+storageState+expired+auth%3A+how+to+re-authenticate&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.