Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Apr 2, 2025

Description

Part of ORGS-621

Allows to pass treatPendingAsSignedOut as an option to useAuth - refer to the following behavior when a session has a pending status:

// userId is undefined, since pending is treat as signed-out state (default behavior)
const { userId } = useAuth() 

// userId is defined, since pending is treat as signed-out state (opt-in behavior)
const { userId } = useAuth({ treatPendingAsSignedOut: true })

Globally changing the default:

<ClerkProvider treatPendingAsSignedOut={false} />

Example from Nuxt route middleware:

const isProtectedRoute = createRouteMatcher(['/dashboard(.*)', '/forum(.*)'])

export default defineNuxtRouteMiddleware((to) => {
  const { userId } = useAuth()

  // If the user has a pending session, they aren't allowed to access
  // the protected route and are redirected to the sign-in page
  // If the sign-in page renders `SignIn`, then it'll redirect to `/tasks` internal route on component mount
  if (!userId.value && isProtectedRoute(to)) {
    return navigateTo('/sign-in')
  }
})

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:

@LauraBeatris LauraBeatris self-assigned this Apr 2, 2025
@changeset-bot
Copy link

changeset-bot bot commented Apr 2, 2025

🦋 Changeset detected

Latest commit: 2950332

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

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

@vercel
Copy link

vercel bot commented Apr 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2025 9:21pm

@LauraBeatris LauraBeatris changed the title chore(clerk-react): Update useAuth to handle pending session as signed-out [wip] chore(clerk-react): Update useAuth to handle pending session as signed-out Apr 2, 2025
@LauraBeatris LauraBeatris force-pushed the laura/pending-use-auth branch from 4a9be7a to ea4d622 Compare April 2, 2025 10:27
@LauraBeatris LauraBeatris changed the title [wip] chore(clerk-react): Update useAuth to handle pending session as signed-out [wip] chore(shared,vue,nextjs,astro,clerk-react): Update useAuth to handle pending session as signed-out Apr 2, 2025
@LauraBeatris LauraBeatris changed the title [wip] chore(shared,vue,nextjs,astro,clerk-react): Update useAuth to handle pending session as signed-out chore(shared,vue,nextjs,astro,clerk-react): Update useAuth to handle pending session as signed-out Apr 2, 2025
@LauraBeatris LauraBeatris requested a review from a team April 2, 2025 10:59
@LauraBeatris LauraBeatris marked this pull request as ready for review April 2, 2025 11:04
Base automatically changed from laura/clerk-signed-in-pending to main April 2, 2025 18:22
@LauraBeatris LauraBeatris force-pushed the laura/pending-use-auth branch from 396134b to ff18c63 Compare April 2, 2025 18:23
Copy link
Member

@wobsoriano wobsoriano left a comment

Choose a reason for hiding this comment

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

Looks good on the Vue and Astro side. Thanks for abstracting the auth state logic away 🙇🏼

'@clerk/vue': patch
---

Update `useAuth` to handle pending sessions as signed-out by default, with opt-out via `useAuth({ treatPendingAsSignedOut: false })` or `<ClerkProvider treatPendingAsSignedOut={false} />`
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll spin up different changeset per package since <ClerkProvider treatPendingAsSignedOut={false} /> is specific to React

@LauraBeatris LauraBeatris force-pushed the laura/pending-use-auth branch from d44cf5f to 2950332 Compare April 3, 2025 21:20
@LauraBeatris LauraBeatris merged commit 6112420 into main Apr 3, 2025
30 checks passed
@LauraBeatris LauraBeatris deleted the laura/pending-use-auth branch April 3, 2025 21:31
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.

5 participants