René's URL Explorer Experiment


Title: Sign-in token redemption is unusable in an in-app browser: `session_exists`, then `sign_in_token_already_used` · Issue #9451 · clerk/javascript · GitHub

Open Graph Title: Sign-in token redemption is unusable in an in-app browser: `session_exists`, then `sign_in_token_already_used` · Issue #9451 · clerk/javascript

X Title: Sign-in token redemption is unusable in an in-app browser: `session_exists`, then `sign_in_token_already_used` · Issue #9451 · clerk/javascript

Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk support via email or Discord (if you hav...

Open Graph Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...

X Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...

Opengraph URL: https://github.com/clerk/javascript/issues/9451

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sign-in token redemption is unusable in an in-app browser: `session_exists`, then `sign_in_token_already_used`","articleBody":"### Preliminary Checks\n\n- [x] I have reviewed the documentation: https://clerk.com/docs\n\n- [x] I have searched for existing issues: https://github.com/clerk/javascript/issues\n\n- [x] I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)\n\n- [x] This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.\n\n\n### Reproduction\n\nhttps://github.com/scoobydrew83/worthsync\n\n### Publishable key\n\npk_live_Y2xlcmsud29ydGhzeW5jLmNvbSQ\n\n### Description\n\n## Summary\n\nWe implemented Clerk's documented native→web session handoff (mint a sign-in token on the\nbackend, open a URL in the app's in-app browser, redeem with `signIn.ticket()`). It cannot be\nmade to work as documented. Two distinct defects compound, and the fix for the second one is a\nPR from a Clerk engineer that was closed without merging.\n\nWe have a working workaround. We are filing this because the workaround depends on undocumented\nbehaviour that could change under us, and because the documented path is broken for anyone who\ntries it.\n\n## Environment\n\n| | |\n|---|---|\n| `@clerk/nextjs` | 7.5.1 (also reported by others on 7.6.3 and 7.7.4) |\n| `clerk-js` | 6.x, served from our custom FAPI domain |\n| `@clerk/expo` | 4.2.3 |\n| Next.js | 16, App Router, deployed on Cloudflare Workers via OpenNext |\n| Instance | **Production**, custom FAPI domain, **single session mode** |\n| Native | Expo SDK 57, `expo-web-browser` → SFSafariViewController (iOS) / Custom Tabs (Android) |\n\n## What we're trying to do\n\nThe mobile app signs the user in natively with `@clerk/expo`. Several screens are web-only\n(reports, household sharing/invites, policy documents, account deletion), and the app opens them\nin an in-app browser. We want those to open **already signed in**.\n\nPer the docs, we:\n\n1. `POST /v1/sign_in_tokens` with `{ user_id, expires_in_seconds: 60 }`\n2. Open `https://app.example.com/sign-in-with-token?token=\u003cTOKEN>&redirect_url=/settings/privacy`\n3. On that page, call `signIn.ticket({ ticket })` then `signIn.finalize({ navigate })`\n\nAccount deletion in particular is an **App Store Review Guideline 5.1.1(v)** requirement, so this\nis not a nice-to-have — a reviewer meeting a sign-in wall is a rejection.\n\n---\n\n## Defect 1 — `session_exists` makes the documented example a silent no-op\n\nThe in-app browser usually already holds a Clerk session (on iOS, one our own app created during\na previous handoff — SFSafariViewController has a persistent per-app store). In single-session\nmode, `signIn.ticket()` then fails:\n\n```\nsession_exists — \"Session already exists\"\n\"You're currently in single session mode. You can only be signed into one account at a time.\"\n```\n\n**The official example does not handle this.** From\n`docs/guides/development/custom-flows/authentication/embedded-email-links.mdx`:\n\n```tsx\nif (!signInToken || user || loading) {\n  return          // \u003c-- silently does nothing when a session exists\n}\n```\n\nSo the documented flow's behaviour in our scenario is \"quietly do nothing,\" which is\nindistinguishable from a bug in the caller.\n\n**`setActive({ session: null })` does not clear it.** Reading `clerk-js` (`core/clerk.ts`),\n`#touchCurrentSession` early-returns when the session is null and `client.sessions` is never\nmutated — it issues no FAPI request at all. The Frontend API still sees the session. This is not\nobvious from the API surface, and \"set the active session to nothing\" is exactly what a reader\nwould reach for.\n\nOnly `client.removeSessions()` / `signOut()` actually issue `DELETE /v1/client/sessions`.\n\n**Prior report:** [clerk/javascript#8044](https://github.com/clerk/javascript/issues/8044) —\nsame defect, filed in March of this year, **closed by a staleness bot with zero maintainer\nreplies**, and re-reported by two more users on 2026-07-30 against `@clerk/nextjs@7.6.3`. It is\nnot fixed in any released version.\n\n---\n\n## Defect 2 — `signOut()` triggers a Safari hard reload that respends the single-use token\n\nWorking around Defect 1 by signing out first produces the next failure:\n\n```\nsign_in_token_already_used_code — \"Sign in token has already been used.\"\n```\n\n**This reproduces on iOS and not on Android, with identical code.**\n\nThe mechanism is documented in Clerk's own\n[PR #7873](https://github.com/clerk/javascript/pull/7873) by `manovotny`:\n\n1. `clerk-js` calls `onBeforeSetActive()` during sign-out **deliberately without** the\n   `'sign-out'` intent (there is a comment explaining why).\n2. `@clerk/nextjs` skips its `invalidateCacheAction()` server action **only when that intent is\n   `'sign-out'`** — so for `signOut()` the action fires.\n3. `invalidateCacheAction()` calls `cookies().delete()` inside a server action, which in\n   Next.js 15+ re-renders the current page's RSC tree as part of the response.\n4. **In Safari that RSC delivery fails (`TypeError: Load failed`), and Next.js falls back to a\n   hard browser navigation.**\n5. The reload restores the URL **from Next's internal router state** — token included — and the\n   page redeems the already-consumed token.\n\nThat PR proposes the fix (drop the `&& intent === 'sign-out'` condition). It is **closed and\nnever merged**; the condition is still present in `main` today.\n\nNote this also means `history.replaceState` is not a sufficient mitigation, because Next's\nrouter state is not updated by it — as the PR itself points out.\n\nPossibly related and still open:\n[clerk/javascript#9405](https://github.com/clerk/javascript/issues/9405) (`invalidateCacheAction`\nfiring on Next 16 + `@clerk/nextjs` 7.5.x–7.7.x, different symptom, same machinery).\n\n---\n\n## What we shipped, in case it's useful to others\n\n```tsx\n// 1. Guard must survive a full page RELOAD — not a re-render, not a remount.\n//    A useRef or module-scope flag is reborn in the new document.\nconst attemptKey = `ticket_attempt:${token.slice(-24)}`;\nconst alreadyAttempted = sessionStorage.getItem(attemptKey) !== null;\nsessionStorage.setItem(attemptKey, \"1\");\n\n// 2. If a previous document already spent it, don't redeem — recover.\nif (alreadyAttempted) {\n  const live = clerk.client?.signedInSessions?.[0];\n  if (live) { await clerk.setActive({ session: live.id, navigate: ... }); return; }\n}\n\n// 3. Skip redemption entirely when the browser already holds the right user.\nconst existing = clerk.client?.signedInSessions ?? [];\nconst mine = existing.find(s => s.user?.id === expectedUserId);\nif (mine) { await clerk.setActive({ session: mine.id, navigate: ... }); return; }\n\n// 4. Otherwise clear server-side. removeSessions(), NOT signOut() — signOut()\n//    routes through onBeforeSetActive and triggers Defect 2.\nif (existing.length > 0) await clerk.client.removeSessions();\n\nconst { error } = await signIn.ticket({ ticket: token });\n```\n\nTwo things worth calling out for the docs:\n\n- `clerk.client.signedInSessions` is the only reliable signal here.\n  `useAuth().isSignedIn` is seeded from server-rendered state and reads `false` until `clerk-js`\n  has fetched `/v1/client`, so guarding on it means the clear never runs.\n- After a successful `POST /v1/client/sign_ins` the session is attached to\n  `clerk.client.signedInSessions`, but `clerk.session` stays `null` until `setActive` runs — so\n  `if (clerk.session)` is the wrong recovery check.\n\n---\n\n## What we're asking for\n\n1. **Ship PR #7873, or an equivalent fix.** Right now `signOut()` on Safari + Next.js 15/16 can\n   trigger a hard reload that replays the current URL. That is a general hazard, not specific to\n   ticket flows — any page holding one-time state in its query string is exposed.\n\n2. **Reopen or comment on #8044.** It is a real, reproducible defect that was closed by a bot\n   without a maintainer ever looking at it, and it has since been re-reported against 7.6.3.\n\n3. **Fix the `accept-token` docs example.** As written it silently no-ops when a session already\n   exists. It should show the existing-session path — that is the *common* case in any embedded\n   browser, not an edge case.\n\n4. **Is there a supported way to do native→webview session handoff?** We're aware of\n   [clerk-docs#2483](https://github.com/clerk/clerk-docs/issues/2483) (\"Clerk does not support\n   Webviews environments\") and\n   [clerk/javascript#3880](https://github.com/clerk/javascript/issues/3880). We also found a\n   closed, unmerged `clerk-ios` PR\n   ([#357](https://github.com/clerk/clerk-ios/pull/357)) adding `prepareAuthenticatedWebURL()`\n   backed by `POST /v1/client/prepare_webview`, which is exactly this use case.\n\n   **Is `/v1/client/prepare_webview` live on production FAPI?** If so we would use it and delete\n   all of the above. If not, is a supported handoff on the roadmap?\n\n5. **Would you consider a `signIn.ticket()` option that replaces an existing session** rather\n   than erroring? Every consumer of this API in an embedded browser has to hand-roll the\n   sign-out dance, and getting it wrong burns a single-use token.\n\n## Reproduction\n\nAny production Clerk instance in single-session mode, Next.js 15/16 App Router:\n\n1. Sign in normally in Safari so a session exists.\n2. Mint a sign-in token via `POST /v1/sign_in_tokens`.\n3. Visit `/your-accept-page?token=\u003cTOKEN>` in the same browser.\n4. Call `signIn.ticket({ ticket })` → `session_exists`.\n5. Call `await signOut()` first, then `signIn.ticket({ ticket })` → in Safari,\n   `sign_in_token_already_used_code`, because the page reloaded and redeemed twice.\n\nAndroid/Chrome does not reproduce step 5.\n\n### Environment\n\n```Shell\n| | |\n|---|---|\n| `@clerk/nextjs` | 7.5.1 (also reported by others on 7.6.3 and 7.7.4) |\n| `clerk-js` | 6.x, served from our custom FAPI domain |\n| `@clerk/expo` | 4.2.3 |\n| Next.js | 16, App Router, deployed on Cloudflare Workers via OpenNext |\n| Instance | **Production**, custom FAPI domain, **single session mode** |\n| Native | Expo SDK 57, `expo-web-browser` → SFSafariViewController (iOS) / Custom Tabs (Android) |\n```","author":{"url":"https://github.com/scoobydrew83","@type":"Person","name":"scoobydrew83"},"datePublished":"2026-08-14T01:45:54Z","url":"https://github.com/clerk/javascript/issues/9451"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:037f96f2-0fc0-baf0-87f6-efbd54f94c9d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAD28:1A169A:73E5DB:A356D5:6AFB68E1
html-safe-nonceb3c10b20d3e617d3f76277882d9ef62d14c92511d3ffa9e03c302b93a354dd42
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDI4OjFBMTY5QTo3M0U1REI6QTM1NkQ1OjZBRkI2OEUxIiwidmlzaXRvcl9pZCI6IjkwMzM2NTA1Mzg0Nzc3NDIzMDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5bb02e875275d71aac5c60b192ba29b12cbd309c9935883b57ea14bdda1d250c
hovercard-subject-tagissue:5147386396
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/clerk/javascript/9451/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7d9ba0cbe1117d448c26369584d986029f9fdbc9e42804b7c1a2387821583659/clerk/javascript/issues/9451
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7d9ba0cbe1117d448c26369584d986029f9fdbc9e42804b7c1a2387821583659/clerk/javascript/issues/9451
og:image:altPreliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamescoobydrew83
hostnamegithub.com
expected-hostnamegithub.com
Noneea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94
turbo-cache-controlno-preview
go-importgithub.com/clerk/javascript git https://github.com/clerk/javascript.git
octolytics-dimension-user_id49538330
octolytics-dimension-user_loginclerk
octolytics-dimension-repository_id438331492
octolytics-dimension-repository_nwoclerk/javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id438331492
octolytics-dimension-repository_network_root_nwoclerk/javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release59ef97164c52cf59bd10558ddec9c4f482763988
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/clerk/javascript/issues/9451#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fclerk%2Fjavascript%2Fissues%2F9451
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fclerk%2Fjavascript%2Fissues%2F9451
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=clerk%2Fjavascript
Reloadhttps://github.com/clerk/javascript/issues/9451
Reloadhttps://github.com/clerk/javascript/issues/9451
Reloadhttps://github.com/clerk/javascript/issues/9451
clerkhttps://github.com/clerk
javascripthttps://github.com/clerk/javascript
Codehttps://github.com/clerk/javascript
Issues45 (45)https://github.com/clerk/javascript/issues
Pull requests110 (110)https://github.com/clerk/javascript/pulls
Discussionshttps://github.com/clerk/javascript/discussions
Actionshttps://github.com/clerk/javascript/actions
Security and quality6 (6)https://github.com/clerk/javascript/security
Insightshttps://github.com/clerk/javascript/pulse
https://github.com/clerk/javascript
New issuehttps://github.com/login?return_to=https://github.com/clerk/javascript/issues/9451
New issuehttps://github.com/login?return_to=https://github.com/clerk/javascript/issues/9451
Sign-in token redemption is unusable in an in-app browser: session_exists, then sign_in_token_already_usedhttps://github.com/clerk/javascript/issues/9451#top
needs-triageA ticket that needs to be triaged by a team memberhttps://github.com/clerk/javascript/issues?q=state%3Aopen%20label%3A%22needs-triage%22
https://github.com/scoobydrew83
scoobydrew83https://github.com/scoobydrew83
on Aug 14, 2026https://github.com/clerk/javascript/issues/9451#issue-5147386396
https://clerk.com/docshttps://clerk.com/docs
https://github.com/clerk/javascript/issueshttps://github.com/clerk/javascript/issues
https://clerk.com/discordhttps://clerk.com/discord
https://github.com/scoobydrew83/worthsynchttps://github.com/scoobydrew83/worthsync
clerk/javascript#8044https://github.com/clerk/javascript/issues/8044
PR #7873https://github.com/clerk/javascript/pull/7873
clerk/javascript#9405https://github.com/clerk/javascript/issues/9405
fix(nextjs): skip invalidateCacheAction on Next.js 15+ for all auth transitions #7873https://github.com/clerk/javascript/pull/7873
signIn.create({ strategy: 'ticket' }) silently fails when user has an active session #8044https://github.com/clerk/javascript/issues/8044
clerk-docs#2483https://github.com/clerk/clerk-docs/issues/2483
clerk/javascript#3880https://github.com/clerk/javascript/issues/3880
#357https://github.com/clerk/clerk-ios/pull/357
scoobydrew83https://github.com/scoobydrew83
needs-triageA ticket that needs to be triaged by a team memberhttps://github.com/clerk/javascript/issues?q=state%3Aopen%20label%3A%22needs-triage%22
on Aug 14, 2026https://github.com/clerk/javascript/issues/9451#event-29433920955
https://github.com/ArjunCodess
ArjunCodesshttps://github.com/ArjunCodess
on Sep 19, 2026https://github.com/clerk/javascript/issues/9451#issuecomment-5740469258
Sign up for freehttps://github.com/signup?return_to=https://github.com/clerk/javascript/issues/9451
Sign in to commenthttps://github.com/login?return_to=https://github.com/clerk/javascript/issues/9451
needs-triageA ticket that needs to be triaged by a team memberhttps://github.com/clerk/javascript/issues?q=state%3Aopen%20label%3A%22needs-triage%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.