`signIn.sso()` (Future API) silently does nothing for OAuth when a SignIn already exists

オープン
#10,709 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
next.js, react, typescript

調査の方向性

Start in packages/clerk-js/src/core/resources/SignIn.ts and read SignInFuture.sso, focusing on how shouldCreateSignIn handles an existing sign-in for OAuth strategies. Reproduce with the component and steps in the issue, then verify that sso() starts OAuth or returns a meaningful error when a sign-in already has an id. The issue does not name a test file.

索引モデルが issue の本文から書いたものです。

説明

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 have, no need to open an issue here)
  • This issue is not a question, general help request, or anything other than a bug report directly related to Clerk.
Reproduction

No public repository. Minimal component below (Next.js App Router, Future API). Happy to put together a repo if that helps.

Publishable key

Development instance, available on request.

Description

Related to #9006, but the trigger is different: no reset() is involved, and the button stays inert across page reloads.

With the Future API (useSignIn() from @clerk/nextjs, not /legacy), signIn.sso({ strategy: 'oauth_google', ... }) resolves with { error: null } without sending any request and without navigating, as soon as the client already holds a SignIn that has an id and no pending external redirect. A failed attempt with an unknown identifier is enough to get there. Since that sign-in lives on the client, it survives page reloads: "Continue with Google" stays dead for that browser until the sign-in goes away.

Steps to reproduce:

'use client';
import { useSignIn } from '@clerk/nextjs';

export default function Page() {
  const { signIn } = useSignIn();
  return (
    <>
      <button onClick={() => signIn?.create({ identifier: '[email protected]' })}>
        1. Attempt with an unknown identifier
      </button>
      <button
        onClick={async () => {
          const { error } = await signIn!.sso({
            strategy: 'oauth_google',
            redirectUrl: '/',
            redirectCallbackUrl: `${window.location.origin}/sso-callback`,
          });
          console.log('sso resolved', { error, id: signIn!.id, status: signIn!.status });
        }}
      >
        2. Continue with Google
      </button>
    </>
  );
}
  1. Click 1. The attempt fails with form_identifier_not_found, and the client now holds a SignIn (sia_…) with status needs_identifier. In our app we first ran into it after a failed signIn.password().
  2. Click 2.
  3. Optionally reload the page and click 2 again: same result.

Expected behavior:

sso() starts a new OAuth attempt and navigates to the provider, or at least resolves with an error saying why it can't.

Actual behavior:

sso() resolves with { error: null }. No request is sent to the Frontend API, nothing navigates, and signIn.id is unchanged.

Root cause (clerk-js 6.41.0, unchanged on main / 6.42.3), in SignInFuture.sso (packages/clerk-js/src/core/resources/SignIn.ts):

const hasPendingRedirect = !!this.#resource.firstFactorVerification.externalVerificationRedirectURL;
const wouldReplayStaleRedirect = strategy !== 'enterprise_sso' && hasPendingRedirect;
const shouldCreateSignIn = !this.#resource.id || wouldReplayStaleRedirect;

When the sign-in already has an id and no external redirect URL, shouldCreateSignIn is false. For oauth_* strategies nothing else runs afterwards (prepare_first_factor is only called for enterprise_sso), so pendingHandOff() returns null and the method returns without doing anything. The classic authenticateWithRedirect doesn't have this problem, since it creates a new sign-in unless continueSignIn is set.

Workaround without internals: when signIn.id is set, call signIn.reset(), then call sso() from an effect on the fresh signIn the hook returns on the next render. In 6.41.0 the reset does reach the hook on the next render; it just can't be used inside the same handler, which is #9006.

Possible fixes:

  • create a new sign-in for oauth_* strategies when reusing the existing one would not produce a redirect, or
  • resolve with an error instead of a silent no-op.
Environment
@clerk/nextjs: 7.3.2
@clerk/react: 6.6.1
@clerk/shared: 4.10.1
@clerk/clerk-js: 6.41.0 (loaded from the Frontend API)
next: 15.5.18
react: 18.2.0
OS: macOS; browser: Chromium-based
主要言語
TypeScript
スター
1.8k
フォーク
492
平均マージ
1日 8時間
マージ済み PR(30日)
374

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

clerk/javascript のほかの issue

clerk/javascript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。