Skip to content

Conversation

@LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Mar 17, 2025

Description

Resolves ORGS-581

Handles navigation to next tasks on an after-auth flow. Once all tasks get completed, it navigates to the redirectUrlComplete option, which defaults to after sign-in/sign-up URL based on the Clerk.client state.

Developer flows

For AIO components, there's no signature changes and it'll work out of the box

For custom flows, Clerk.nextTask should be called after performing a FAPI mutation that resolves a task. Here's an example for the upcoming force MFA task:

await fapiClient.configureTotp(...) 
await Clerk.__experimental_nextTask()

Building your on custom React "onboarding" components:

function MyFirstOnboardingPage(){ 
  const clerk = useClerk()

  const handleOrganizationSelection = async (organization: string) => {
   // Select the organization into the current session 
    await setActive({ organization })

   // Proceed with verifying if there's a next task, either navigating to it 
   // or to `redirectUrlComplete` once session transitions to active
    await clerk.__experimental_nextTask()
  }

  return <MyCustomOrganizationList onOrgSelection={handleOrgSelection} />
}

function MySecondOnboardingPage(){ 
  const clerk = useClerk()
  return <ConfigureMFA onSuccess={clerk.__experimental_nextTask} />
}

CleanShot.2025-03-17.at.19.07.02-converted.mp4

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 Mar 17, 2025
@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2025

🦋 Changeset detected

Latest commit: f8b7a53

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

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

@vercel
Copy link

vercel bot commented Mar 17, 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 Mar 21, 2025 9:59am

@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch from f644710 to d63a9f5 Compare March 17, 2025 21:53
@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch from d63a9f5 to ccc0bd2 Compare March 17, 2025 22:05
@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch from ccc0bd2 to cdca177 Compare March 17, 2025 22:09
@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch 2 times, most recently from 280fbf3 to 714a946 Compare March 17, 2025 22:15
@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch from 714a946 to 54f5b52 Compare March 17, 2025 22:17
@LauraBeatris LauraBeatris requested review from a team, brkalow and panteliselef March 17, 2025 22:17
@LauraBeatris LauraBeatris changed the title feat(clerk-js,types): Navigate to next task feat(clerk-js,react,types): Navigate to next task Mar 17, 2025
@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch from 54f5b52 to 76043f7 Compare March 17, 2025 22:18
@LauraBeatris LauraBeatris changed the title feat(clerk-js,react,types): Navigate to next task feat(clerk-js,clerk-react,types): Navigate to next task Mar 17, 2025
@LauraBeatris LauraBeatris marked this pull request as ready for review March 17, 2025 22:21
@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch from 76043f7 to b0f8a4d Compare March 17, 2025 22:30
status: 'pending',
user: {},
tasks: [{ key: 'org' }],
currentTask: { key: 'org', __internal_getUrl: () => 'https://foocorp.com/add-organization' },
Copy link
Contributor

Choose a reason for hiding this comment

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

For posterity: I'm always just a little nervous of including random routable URLs in tests.

Truly unlikely security threat potential: If we actually GET this URL, and someone knows we're getting it, they could register the domain and have it serve some exploit that gets us to leak our CI secrets.

I'm not even proposing you change this - it's the pattern laid down elsewhere in the test - but when in doubt, I like example.com or cnames of it. It's not routable. https://foocorp.example.com/add-organization is safer in my book.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense! Also just to note that our tests only run if the triggering actor (owner of the PR) has the GitHub org permissions to access secrets, otherwise it'll fail

For URLs like those that are used to trigger navigation rather than HTTP requests, then I think it's fine!

<SessionTask task='org' />
<SessionTask
task='org'
redirectUrlComplete={signInContext.afterSignUpUrl}
Copy link
Contributor

@izaaklauer izaaklauer Mar 20, 2025

Choose a reason for hiding this comment

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

❓ Not afterSignInUrl ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is within the isCombinedFlow routes, so those are the sign-up routes rendered within SignIn component therefore it uses signUpContext

Copy link
Contributor

@izaaklauer izaaklauer left a comment

Choose a reason for hiding this comment

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

A relatively superficial review, but it looks correct and reasonable to me. Left a few comments. 👍

@LauraBeatris LauraBeatris force-pushed the laura/after-auth-next-task branch from ad3a5d3 to f8b7a53 Compare March 21, 2025 09:58
@LauraBeatris LauraBeatris merged commit 3910ebe into main Mar 21, 2025
30 checks passed
@LauraBeatris LauraBeatris deleted the laura/after-auth-next-task branch March 21, 2025 10:29
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.

6 participants