Skip to content

Conversation

@jacekradko
Copy link
Member

@jacekradko jacekradko commented Dec 15, 2025

Description

Ensure useAuth().has is always a function

Fixes: USER-2643

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • The auth API's permission checker (has) is now always available as a callable function, letting callers query specific permissions consistently.
  • Types

    • Public types updated so the permission-check function is represented as a concrete function type rather than undefined.
  • Tests

    • Test suite updated to cover the callable permission-checker and its fallback behavior.
  • Chores

    • Added a changelog entry noting the defaulting of the permission checker.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 15, 2025

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

Project Deployment Review Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Dec 16, 2025 7:31pm

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: 229ca12

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

This PR includes changesets to release 19 packages
Name Type
@clerk/react Patch
@clerk/shared Patch
@clerk/chrome-extension Patch
@clerk/expo Patch
@clerk/nextjs Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nuxt Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue 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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Walkthrough

The has property on the auth hook is now always a function (accepts a payload like { permission: string } and returns boolean). Types, implementation, and tests were updated; resolveAuthState return shapes now include an actor field and has across branches.

Changes

Cohort / File(s) Summary
Type definitions
packages/shared/src/types/hooks.ts
Replaced CheckAuthorizationSignedOut (previously undefined) with CheckAuthorizationWithoutOrgOrUser — a function type (params: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => false. Updated UseAuthReturn.has to reference the concrete function type.
Authorization implementation
packages/shared/src/authorization.ts
resolveAuthState return objects now include an explicit actor field and a has function in more branches; object property ordering adjusted to include actor/has alongside isLoaded, isSignedIn, sessionId, sessionClaims, and userId.
React hooks — tests
packages/react/src/hooks/__tests__/useAuth.test.tsx, packages/react/src/hooks/__tests__/useAuth.type.test.ts
Runtime tests updated to assert has is a Function and to call has({ permission: 'test' }) returning boolean; type tests removed the Exclude<..., undefined> on HasFunction and derive params directly from Parameters<...>.
Changelog / changeset
.changeset/steady-has-default.md
Adds a changeset noting that useAuth().has is always defined (defaults to false when auth data is missing) and bumps @clerk/react and @clerk/shared.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Review packages/shared/src/authorization.ts branches to ensure has behavior and actor consistency.
  • Verify type coherence in packages/shared/src/types/hooks.ts with actual runtime has signature.
  • Confirm test updates in packages/react/src/hooks/__tests__/ reflect intended behavior and cover fallback paths.

Poem

🐰 I hopped through types and fields today,
Where "undefined" once hid away,
Now has speaks clear with boolean cheer,
An actor sits beside it near,
Hopping on, the auth is here! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: making the has property always defined (no longer undefined) with a default fallback to false when auth data is missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/use-auth-has

Comment @coderabbitai help to get the list of available commands and usage tips.

@jacekradko jacekradko changed the title feat: ensure has is always defined feat(react,shared): Ensure has is always defined Dec 15, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 15, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7458

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7458

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7458

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7458

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7458

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7458

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@7458

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7458

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7458

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7458

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7458

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7458

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7458

@clerk/react

npm i https://pkg.pr.new/@clerk/react@7458

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7458

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7458

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7458

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7458

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@7458

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7458

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7458

commit: 229ca12

@jacekradko jacekradko merged commit da415c8 into main Dec 16, 2025
71 of 72 checks passed
@jacekradko jacekradko deleted the feat/use-auth-has branch December 16, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants