refactor(spx-gui): remove jwt-decode and drop local cached username assumptions#3224
refactor(spx-gui): remove jwt-decode and drop local cached username assumptions#3224cn0809 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the authentication flow to rely on canonical, backend-confirmed user data instead of synchronously decoding the username from the JWT access token. It removes the jwt-decode dependency, updates the stores (following, liking, and user) to use the fetched user data, and adds TODOs for future routing and storage improvements. The review feedback highlights a critical robustness issue: if the asynchronous username synchronization fails during sign-in, the application could be left in a corrupted state where it appears signed in but lacks valid user data. It is recommended to wrap these synchronization calls in try-catch blocks to trigger a sign-out and clean up the state upon failure.
There was a problem hiding this comment.
Code Review Summary
This refactor correctly eliminates fragile client-side JWT claim extraction and moves username resolution to a backend-authoritative path. The core direction is sound. A few issues worth addressing:
Highlights:
signInWithAccessTokenis now properlyasyncand awaited — the missingawaitin the prior code was a real buguseModifySignedInUsernamenow fetches canonical identity before cache invalidation — correctfollowing.ts/liking.tsmigration touseSignedInUser()is clean- Typo fixes (
known,access) are appreciated
Issues noted inline below.
Summary
This PR removes reliance on locally cached username hints and tightens how signed-in state is resolved, scoped, and consumed across the app.
Main changes
usernamefield from local auth state and stop eagerly validating sign-in by fetching the signed-in user during token-based sign-in.