feat(script): user impersonation script for local dev - #212
Draft
jerryzhou196 wants to merge 2 commits into
Draft
Conversation
Mint a UW Flow session token for any user via a direct psql lookup and the JWT key in .env, so you can view the site exactly as they see it. Signs byte-for-byte the same HS256 claims as serde.NewSignedJwt, so both Hasura and the Go API accept the token; nothing is written to the DB. - looks users up by id, email, or fuzzy name - interactive fzf picker over the full user table when no user is named - reaches Postgres via host psql or `docker exec postgres psql` - emits a browser-console snippet (localStorage token + user_id) plus --token-only / --json for scripting Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TrJWMd1itog7bn3UfdNvg6
pick_user runs inside a $(...) capture, so stdout is always a pipe even in an interactive shell — the old `[ -t 1 ]` guard therefore blocked the fzf picker in every real run, not just non-interactive ones. fzf draws on /dev/tty regardless of where stdout goes, so test /dev/tty instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TrJWMd1itog7bn3UfdNvg6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
script/impersonate.sh— mint a UW Flow session token for any user so you can view the site exactly as they see it during local development.How it works
The backend hands out an HS256 JWT at login (
flow/api/serde/jwt.go); the frontend just stashes it inlocalStorageundertoken+user_id(src/utils/Auth.tsx). Nothing ties that token to how you logged in — it's a signature over the Hasura claims keyed byHASURA_GRAPHQL_JWT_KEY. So the script:POSTGRES_*creds in.env(hostpsql, ordocker exec postgres psqlwhen no client is installed).serde.NewSignedJwt(singleuserrole + iat/nbf/exp).No impersonation endpoint, no DB writes — the token is indistinguishable from a real login, which is why it's dev-only.
Usage
Flags:
-i/--interactive,-e/--env-file,-t/--ttl,-c/--copy,--token-only,--json. Prints a browser-console snippet that setstoken+user_idand reloads, plus a one-liner to drop back out.Verified against a live stack
{ user { email } }returns only that user's row (row-levelx-hasura-user-idhonored)/auth/refreshvalidated it and issued a fresh tokenfzf🤖 Generated with Claude Code
https://claude.ai/code/session_01TrJWMd1itog7bn3UfdNvg6