Skip to content

feat(react): add useOAuthAuthorize hook - #1217

Merged
joshuaellis merged 3 commits into
feat/SDK-2419from
feat/SDK-2418
Sep 22, 2026
Merged

joshuaellis merged 3 commits into
feat/SDK-2419from
feat/SDK-2418

Conversation

@joshuaellis

Copy link
Copy Markdown
Member

Description

Adds useOAuthAuthorize, a hook that starts the OAuth authorization-code + PKCE flow by delegating to core's startOAuthAuthorization. It returns the bound action directly, matching useOAuthCallback and useLogOut, so apps get one consistent shape for auth callbacks. Config (clientId, redirectUri, organizationId) is read from the instance's auth.oauth, so the hook takes no options.

@joshuaellis
joshuaellis requested a review from a team as a code owner September 11, 2026 12:48
@joshuaellis
joshuaellis requested review from binoy14 and removed request for a team September 11, 2026 12:48
@claude

claude Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @joshuaellis's task in 1m 19s —— View job


Review: no further issues

  • Gather context (diff vs origin/feat/SDK-2419, AGENTS.md, .claude/rules/react-package-conventions.md, monorepo-guidelines.md)
  • Review changes
  • Post findings

No actionable issues found in the 51 added lines.

What I checked
  • Wiring — useOAuthAuthorize = createCallbackHook(startOAuthAuthorization) matches useHandleOAuthCallback.tsx:46 and useLogOut exactly. createCallbackHook memoizes on instance, so the returned callback is stable; startOAuthAuthorization is exported from core at packages/core/src/_exports/index.ts:57.
  • Doc accuracy — the @remarks claim that the returned promise rejects without auth.oauth config is backed by getOAuthOptions in packages/core/src/auth/oauth/oauthActions.ts (covered by oauthActions.test.ts:161, rejects.toThrow(/OAuth is not configured/)). The {@link useHandleOAuthCallback} target exists and is exported; {@link} to sibling hooks is the established pattern in this package.
  • Test — useOAuthAuthorize.test.tsx is a byte-for-byte analogue of useHandleOAuthCallback.test.tsx, including the reliance on Vitest globals for vi/expect. CI reports 100% coverage on the new file. It only asserts wiring, but that's the right scope here since all behaviour lives in core and is tested there.
  • Export surface — added to sdk-react.ts in alphabetical position; purely additive, no semver break. .tsx extension with no JSX matches the sibling auth hooks.
  • Changeset — '@sanity/sdk': minor alongside '@sanity/sdk-react': minor even though this PR touches no core files. That mirrors .changeset/oauth-usehandlecallback.md and .changeset/oauth-usetokens.md in the same stack, so it's the intended lockstep pattern, not an oversight.
  • Cross-package / Renovate — no new dependencies, no React leakage into core; nothing to add to .github/renovate.json.
Not verified locally

I couldn't run pnpm test, pnpm ts:check, pnpm lint, or pnpm fallow audit — the sandbox declined the command. The review is static; CI's coverage and TypeDoc jobs are green on e28d27c.

· branch [`feat/SDK-2418`](https://github.com/sanity-io/sdk/tree/feat/SDK-2418)

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Stats

✅ No significant changes.

All scenario measurements (8)

🗺️ @sanity/sdk / @sanity/sdk · @sanity/sdk / @sanity/sdk/_internal · @sanity/sdk / @sanity/sdk/agent · @sanity/sdk / @sanity/sdk/comlink · @sanity/sdk / @sanity/sdk/dashboard · @sanity/sdk-react / @sanity/sdk-react · @sanity/sdk-react / @sanity/sdk-react/dashboard · @sanity/sdk-react / @sanity/sdk-react/dashboard/_internal · Artifacts

Scenario Kind Bundle (raw / gzip) Gzip change Import time Import change
⚪ @sanity/sdk / @sanity/sdk export 1.14 MB / 259.5 KB None 256 ms +5 ms, +1.8%
⚪ @sanity/sdk / @sanity/sdk/_internal export 599.2 KB / 137.0 KB None 187 ms +1 ms, +0.7%
⚪ @sanity/sdk / @sanity/sdk/agent export 414.5 KB / 90.9 KB None 168 ms -2 ms, -1.4%
⚪ @sanity/sdk / @sanity/sdk/comlink export 260.2 KB / 60.6 KB None 186 ms +2 ms, +1.1%
⚪ @sanity/sdk / @sanity/sdk/dashboard export 105.0 KB / 23.2 KB None 168 ms +1 ms, +0.7%
⚪ @sanity/sdk-react / @sanity/sdk-react export 1.42 MB / 334.3 KB +18 B, +0.0% 302 ms +3 ms, +0.8%
⚪ @sanity/sdk-react / @sanity/sdk-react/dashboard export 827.1 KB / 189.1 KB None 305 ms +3 ms, +0.8%
⚪ @sanity/sdk-react / @sanity/sdk-react/dashboard/_internal export 107.8 KB / 23.7 KB None 188 ms +1 ms, +0.5%

Significant means at least 1.0 KB and 1% gzip, or at least 5 ms and 10% import time.

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

📚 TypeDoc Generation Result

✅ TypeDoc generated successfully!

  • JSON file size: 3.2M
  • Total exports: 449
  • Artifact: typedoc-html-pr-1217
  • HTML docs preview: Download artifact

The package TypeDoc JSON files and combined HTML site have been generated successfully.

@joshuaellis
joshuaellis added this pull request to stack #1218 September 11, 2026 12:51
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 97.34% (🎯 94%) 5894 / 6055
🟢 Statements 96.04% (🎯 93%) 6410 / 6674
🟢 Functions 97.34% (🎯 94%) 1763 / 1811
🟢 Branches 89.97% (🎯 86%) 3402 / 3781
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/react/src/hooks/auth/useOAuthAuthorize.tsx 100% 100% 100% 100%
Generated in workflow #6452 for commit dd8a7d2 by the Vitest Coverage Report Action

@joshuaellis

Copy link
Copy Markdown
Member Author

Actioned: reworded to "the returned promise rejects" and the example now does authorize().catch(console.error). Also updated the {@link} to useHandleOAuthCallback following the rename in #1216.

joshuaellis added a commit that referenced this pull request Sep 17, 2026
@joshuaellis
joshuaellis force-pushed the feat/SDK-2418 branch 2 times, most recently from 4ca6d90 to 0d1ae89 Compare September 21, 2026 09:32
@joshuaellis
joshuaellis force-pushed the feat/SDK-2418 branch 2 times, most recently from 498e42d to e53aa4b Compare September 21, 2026 12:24
@joshuaellis
joshuaellis merged commit 3c783f7 into main Sep 22, 2026
25 checks passed
@joshuaellis
joshuaellis deleted the feat/SDK-2418 branch September 22, 2026 19:05
@squiggler-app squiggler-app Bot mentioned this pull request Sep 22, 2026
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.

3 participants