Skip to content

feat(me): link a signed-in user to their own driver stats - #175

Merged
alchemydc merged 2 commits into
developfrom
feat/my-driver-stats
Sep 15, 2026
Merged

alchemydc merged 2 commits into
developfrom
feat/my-driver-stats

Conversation

@alchemydc

Copy link
Copy Markdown
Owner

Reaching your own stats meant opening an event or the championship and finding yourself in a results table. /me now resolves the signed-in viewer to their Driver row and links straight to it. Addresses driver feedback.

Driver.msrUid has been a unique column since the init migration with no read or write path anywhere in the codebase, so this needed no migration. Resolution prefers that explicit link, then falls back to Driver.nameOnlyHash and only matches when exactly one Driver carries the hash, the same "exactly one candidate or don't guess" rule ingest already uses for merge/adopt. The join key exists because the OAuth callback computes the digest from the MSR profile while it still has the full surname, then discards it; the hash goes in the session, the surname is still never persisted.

computeNameOnlyHash moved from ingest.ts to pii.ts (re-exported, so existing importers are untouched) because ingest.ts top-level-imports better-sqlite3 and the OAuth callback should not pull a native SQLite driver into its bundle.

Reads and writes are split deliberately: resolveSelfDriver is pure read so rendering /me carries no side effect, and the single write is claimSelfDriver, called from the callback and wrapped so it can never fail a login. Cross-league aggregation needed no new code: buildDriverHistory already accepts leagueIds: "all".

The second commit is unrelated to the feature but was found while smoke-testing it: the /login sign-in button was a next/link pointing at a Route Handler that 302s cross-origin to MSR, so the App Router client fetched an RSC payload for it, failed on the redirect, and fell back to a browser navigation, running OAuth step 1 twice per click and minting two request tokens. landing.tsx already used a plain anchor.

Verification

lint, typecheck, test (728 passing across 62 files) and build all clean. New tests/driver-self.test.ts covers 12 cases across both functions, including an ambiguous hash, a row already claimed by another user, and a legacy row with a null nameOnlyHash.

Smoke-tested locally against real dev data: MSR login, /me renders the results card, link lands on the right driver page. Note that the unmatched and unlinkable empty states have unit coverage only and have not been viewed in a browser, and the new card has not been checked at mobile and desktop breakpoints.

Reaching your own stats meant opening an event or the championship and
finding yourself in a results table. /me now resolves the viewer to their
Driver row and links straight to it.

Driver.msrUid has been a unique column since the init migration with no
read or write path anywhere; this is what finally uses it, so no migration
is needed. Matching falls back to Driver.nameOnlyHash, computed at login
from the MSR profile before the full surname is discarded, and only when
exactly one Driver carries the hash -- the same rule ingest already uses
for merge/adopt. computeNameOnlyHash moves to pii.ts (re-exported from
ingest.ts) so the OAuth callback doesn't pull better-sqlite3 into its
bundle.
The target is a Route Handler that 302s cross-origin to MSR, so the App
Router client fetched an RSC payload for it, failed on the redirect, and
fell back to a browser navigation -- running OAuth step 1 twice per click,
minting two request tokens and writing lc_msr_req twice. landing.tsx
already used a plain <a>.
@vercel

vercel Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
launchcontrol Ready Ready Preview Sep 15, 2026 11:33pm UTC

@alchemydc
alchemydc merged commit 9f58b7d into develop Sep 15, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — d9b1fc20 Deployed Sep 15, 2026 by vercel[bot]
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