Skip to content

chore: add logout-all-users recovery script#207

Open
cdtinney wants to merge 1 commit into
mainfrom
cdtinney/spune-down-debug
Open

chore: add logout-all-users recovery script#207
cdtinney wants to merge 1 commit into
mainfrom
cdtinney/spune-down-debug

Conversation

@cdtinney

Copy link
Copy Markdown
Owner

Summary

Adds scripts/logout-all-users.sh, run on the droplet to clear the session table when stale cookies point at user rows the server can't deserialize.

Concretely: after the token-encryption rollout in #204, pre-existing user rows still hold plaintext access/refresh tokens. The new decryptToken path requires a v1: prefix and throws on anything else, so passport's deserializeUser (which calls findUserBySpotifyIdtoUser) throws on every authenticated request — including /api/auth/user/logout. The user has no in-app way to recover.

Wiping the session table breaks the cookie → user mapping. The next request runs the OAuth flow, and findOrCreateUser's ON CONFLICT … DO UPDATE rewrites both token columns with freshly-encrypted (v1:-prefixed) values, so the stale rows fix themselves on next login. No need to touch the users table.

Hardcoded to /opt/spune/docker-compose.yml to match migrate.sh / logs.sh. Uses DELETE over TRUNCATE (works under any privilege level, transactional). Confirmation prompt by default; --yes to skip.

Testing

  • bash -n scripts/logout-all-users.sh — syntax check passes.
  • Manually traced the recovery flow: empty session table → next request has no passport.user on req.session → passport doesn't call deserializeUser → no decrypt error → /api/auth/spotify redirect works → callback runs findOrCreateUser → row rewritten with v1: tokens.

Adds scripts/logout-all-users.sh, run on the droplet to clear the
session table when stale cookies point at user rows the server can't
deserialize (e.g. after a token-encryption rollout, where pre-existing
rows hold plaintext tokens the new decrypt path rejects and every
authenticated request 500s before the user can reach
/auth/user/logout). Once the session table is empty, the next request
runs the OAuth flow, which rewrites the user row with freshly-encrypted
tokens via findOrCreateUser ON CONFLICT. Confirmation prompt by
default; --yes skips.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant