Skip to content

feat: add Convex auth recovery#301

Merged
zbeyens merged 2 commits into
mainfrom
codex/sync-repo-skills
Jul 22, 2026
Merged

feat: add Convex auth recovery#301
zbeyens merged 2 commits into
mainfrom
codex/sync-repo-skills

Conversation

@zbeyens

@zbeyens zbeyens commented Jul 22, 2026

Copy link
Copy Markdown
Member
  • Auto release

🐛 Fixes #299

🟢 95-100% confidence

Phase 🧪 Tests 🌐 Browser
Reproduced Stable binding remains terminal noAuth; Better Auth refresh returns null N/A
Verified 44 focused tests; package/docs builds; bun check; clean autoreview N/A

✅ Outcome

  • Adds useConvexAuthRecovery() with typed status, errors, timeout, and exact concurrent dedupe.
  • Recovers Better Auth and generic auth providers through one canonical kitcn owner.
  • Resolves only after the replacement binding fetches a token and Convex confirms authentication.

⚠️ Caveat

  • Recovery is explicit; apps own foreground/network/retry trigger policy and must not invoke it for intentional sign-out.

🏗️ Design

  • Rebinds through provider-controlled callback identity.
  • Correlates completion to the exact replacement binding.
  • Does not patch client.setAuth, remount descendants, or depend on Convex private callbacks.

🧪 Verified

  • bun test packages/kitcn/src/react/auth-store.test.tsx packages/kitcn/src/auth-client/convex-auth-provider.test.tsx packages/kitcn/src/react/index.test.ts
  • bun --cwd packages/kitcn build
  • bun --cwd www build
  • bun run intent:validate plus skill stale audit
  • bun check
  • final autoreview: clean

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
better-convex Ready Ready Preview, Comment Jul 22, 2026 7:38pm

Request Review

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2519738

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
kitcn Patch
@kitcn/resend Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@zbeyens
zbeyens merged commit 3248105 into main Jul 22, 2026
5 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de71b7a934

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

| `useMaybeAuth()` | `boolean` | Has token (optimistic, may not be verified) |
| `useIsAuth()` | `boolean` | Server-verified authentication |
| `useAuthGuard()` | `() => boolean` | Guard mutations, returns true if blocked |
| `useConvexAuthRecovery()` | `{ recover, status, error }` | Rebind Convex auth after a transient token failure |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Regenerate the local kitcn skill mirror

This updates the published kitcn skill source, but the generated mirror at .agents/skills/kitcn/references/features/auth.md still lacks the new useConvexAuthRecovery row and recovery section, so repo-local agents will read stale auth guidance until the mirror is regenerated and committed. Please run bun tooling/sync-kitcn-skill.ts or bun install and include the generated diff.

AGENTS.md reference: AGENTS.md:L6-L7

Useful? React with 👍 / 👎.

Comment on lines +392 to +396
if (!pending.isBound || snapshot.isLoading) {
return;
}
if (snapshot.isAuthenticated) {
settleRecovery(null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Correlate success to the replacement auth callback

When a recovery starts, pending.isBound only proves the replacement fetcher was invoked; the later snapshot.isAuthenticated value is the global Convex auth state, so a stale onChange(true) from the previous binding or any other auth-state transition after the new fetch starts can resolve recover() before Convex has accepted the replacement binding. In that race, callers proceed as if recovery succeeded even though the new binding may still be rejected; the confirmation needs to be versioned to the replacement binding's own auth callback, not just any authenticated snapshot.

Useful? React with 👍 / 👎.

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.

Proposal: first-class Convex auth recovery (rebind after AuthenticationManager reaches terminal noAuth)

1 participant