javascript icon indicating copy to clipboard operation
javascript copied to clipboard

signIn.create({ strategy: 'ticket' }) silently fails when user has an active session

Open pedrobarretocw opened this issue 8 months ago • 4 comments

Description

When accepting an organization invitation via the custom flow documented here, signIn.create({ strategy: 'ticket' }) silently fails if the user already has an active session on the application side.

Steps to reproduce

  1. User A is signed in and has an active organization (org1)
  2. User B invites User A to org2 via organizations.createOrganizationInvitation
  3. User A clicks the invitation email link
  4. Clerk FAPI redirects to the app with __clerk_status=sign_in and __clerk_ticket=<token>
  5. The custom flow calls signIn.create({ strategy: 'ticket', ticket: token })
  6. The call does not throw an error, but the invitation stays pending — the user is never added to org2

Root cause

Clerk FAPI lives on a different domain than the application (e.g., clerk.example.com vs localhost:3001 or app.example.com). Because of this, FAPI cannot detect the user's existing session cookie and returns __clerk_status=sign_in, indicating the user needs to sign in.

However, on the application side, the user already has an active session. When signIn.create({ strategy: 'ticket' }) is called with this conflicting state (active session + sign_in ticket), it fails silently — no error is thrown, but the invitation is not accepted.

Expected behavior

Either:

  1. signIn.create({ strategy: 'ticket' }) should work correctly even when there's an active session (handling the conflict internally), or
  2. It should throw a clear error indicating the session conflict so developers can handle it

Workaround

We had to call signOut() before signIn.create() when the user is already signed in:

const { isSignedIn } = useUser();
const { signOut } = useClerk();

if (isSignedIn) {
  await signOut();
}

const signInAttempt = await signIn.create({
  strategy: "ticket",
  ticket: token,
});

Additional context

  • The docs example guards the sign_in effect with || organization which prevents the effect from running entirely when the user already has an active org — making the documented approach unusable for users who are already members of another organization.
  • Next.js 15, @clerk/nextjs latest
  • Tested in development (localhost) and the behavior is consistent

pedrobarretocw avatar Mar 11 '26 18:03 pedrobarretocw

Hello 👋

We currently close issues after 40 days of inactivity. It's been 30 days since the last update here. If we missed this issue, please reply here. Otherwise, we'll close this issue in 10 days.

As a friendly reminder: The best way to see an issue fixed is to open a pull request. If you're not sure how to do that, please check out our contributing guide.

Thanks for being a part of the Clerk community! 🙏

github-actions[bot] avatar Apr 11 '26 00:04 github-actions[bot]

Hello again 👋

After 40 days of no activity, we'll close this issue. Keep in mind, I'm just a robot, so if I've closed this issue in error, please reply here and my human colleagues will reopen it.

As a friendly reminder: The best way to see an issue fixed is to open a pull request. If you're not sure how to do that, please check out our contributing guide.

Thanks for being a part of the Clerk community! 🙏

github-actions[bot] avatar Apr 21 '26 00:04 github-actions[bot]

hi! I'm still reproducing this issue with @clerk/[email protected].

the invited user is already signed in with the exact email address that received the organization invitation. however, when the invitation link is opened in the same browser session, clerk redirects to our custom URL with:

__clerk_status=sign_in

according to the documentation, this scenario should return complete because the invited user already exists and is signed in.

we confirmed the status by temporarily removing all of our invitation logic and rendering the raw __clerk_status value. this happens before our application calls signIn.ticket(), so it is not caused by our client-side flow.

we also confirmed that our clerk version includes the fix from #8219 / #8641.

we understand that development instances use a different cross-domain session architecture, but this makes the documented custom organization invitation flow unreliable during development and causes an active session to conflict with signIn.ticket().

could you please reopen and fix this issue, or clarify the officially supported way to handle it? specifically:

  • should complete work reliably when the active session belongs to the invited email?
  • is this limitation exclusive to development instances?
  • how should an application safely distinguish the correct active user from a different active user when clerk returns sign_in for both?

thanks!

wmfrancismorgan avatar Jul 30 '26 01:07 wmfrancismorgan

Hey

we are also experiencing this issue, we haven't been able to create a user journey where the status is completed (account exists and is signed in with the same email of the invitation)

Could you please assist us?

hello-alejandro-1 avatar Jul 30 '26 16:07 hello-alejandro-1