mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 11:48:24 +01:00
Drops the "isReturning" gate in decideHealPatch so the heal fires on first sign-in too. When a user signs in with OAuth (GitHub / Google / Twitter) and we can derive a unique username from their display name or email local-part, we set it + onboardedAt right there in the JWT callback. They land authenticated with onboardingComplete=true and middleware sends them straight to /control instead of via /onboarding. User-visible effect: GitHub OAuth → /control in ONE page load instead of two. The /control empty state's GitHubRepoSuggestions / LocalDev- Suggestions / FleetRunnerAutoMint then take over from there. Fallback (still works): users whose suggested username collides with an existing one, or whose display name + email can't yield ≥2 chars of [a-z0-9-], get null patch → middleware sends them to /onboarding to pick manually. The page is no longer a forced gate — just a fallback for the edge cases. Side benefit: also skips the wasted "onboardedAt-only" write that the old logic would do for returning users without a valid username, since onboardedAt without a valid username is a no-op (isOnboardingComplete still gates on both). The /settings → Profile editor lets users change the auto-picked username later, so we're not stealing their choice — just defaulting it. Tests: 7/7 pass (npm run test:onboarding-heal). Updated existing brand-new-user assertion to reflect the new policy and added a collision-fallback test case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>