fix(auth): derive client state from wallet connection - #962
Open
nasalehj wants to merge 1 commit into
Open
Conversation
|
@nasalehj Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Closes #815
The client auth hook now derives authentication from the canonical wallet store after client hydration instead of treating an
auth-tokencookie as proof of identity. It returns the connected wallet address, never the0x...placeholder, and preserves the session fields consumed byAuthGuard.Why
The previous hook trusted cookie presence or an unverified JWT payload, so expired, malformed, and forged cookies could render authenticated UI. It also fabricated the wallet address. Browser code cannot verify the server-signed JWT without exposing the secret, so the existing connected-wallet state is used as the client UI source of truth while server middleware remains responsible for cookie verification.
What was built
src/hooks/useAuth.tssrc/store/walletStore; connected wallet address is returned only whenisConnectedandaddressare both present.src/hooks/__tests__/useAuth.test.tsuseAuth.tsThe focused tests mock the canonical wallet store and use a real hook render; no cookie parsing or JWT client verification path remains in the implementation.
Integration changes outside
src/hooks/useAuth.ts— reduced to a compatibility re-export ofsrc/hooks/useAuth.tsso duplicate implementations cannot diverge.Acceptance criteria coverage
src/hooks/useAuth.ts,src/hooks/__tests__/useAuth.test.ts— cookie-only and malformed/expired payload tests pass)src/hooks/useAuth.ts,src/hooks/__tests__/useAuth.test.ts— connected address and null/disconnected assertions)src/hooks/useAuth.ts,useAuth.ts— duplicate mock implementation removed)src/hooks/__tests__/useAuth.test.ts— 5/5 passing)eslint-plugin-jsdoc; the issue-specific suite passes.Deliberately deferred
Test plan
npx prettier --check src/hooks/useAuth.ts src/hooks/__tests__/useAuth.test.ts useAuth.ts— all matched files pass.npm test -- --runInBand src/hooks/__tests__/useAuth.test.ts— 5/5 passing.npm run typecheck— fails on pre-existing syntax errors in unrelated files includingsrc/app/compare/page.tsx,src/components/ComparisonBar.tsx,src/components/PropertyCard.tsx,src/components/TransactionConfirmation.tsx,src/lib/toast.ts, andsrc/stories/ResponsiveContainerExample.stories.ts; the baseline also reports an existingsrc/components/CartSidebar.tsxsyntax error.npm test -- --runInBand— 63/141 suites passing; 982/1149 tests passing. Failures are existing repository issues including incomplete viem mocks, malformed unrelated source/tests, and unrelated component assertions.npx eslint src/hooks/useAuth.ts src/hooks/__tests__/useAuth.test.ts useAuth.ts --max-warnings=0— cannot start becauseeslint-plugin-jsdocis not installed.npm run build— stops at the same pre-existing typecheck failures.Env vars / Notes
No new environment variables, migrations, or API changes.