Skip to content

fix(kit): isolate social auth and migrate Apple to Capawesome - #106

Merged
rdlabo merged 3 commits into
mainfrom
fix/social-auth-boundaries
Sep 7, 2026
Merged

fix(kit): isolate social auth and migrate Apple to Capawesome#106
rdlabo merged 3 commits into
mainfrom
fix/social-auth-boundaries

Conversation

@rdlabo

@rdlabo rdlabo commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Social authentication could continue after a Firebase user switch, and the combined entry point forced Apple-only consumers to resolve Facebook's native plugin. Apple errors also lost cancellation information, and web access tokens were returned as authorization codes.

Split Apple and Facebook into optional provider entry points, pin the authenticated User across asynchronous boundaries, and reject overlapping Apple/Facebook/Google flows on the same Auth instance through a shared guard. Keep the old /auth-firebase/social functions and types as source-compatible aliases with emitted @deprecated notices.

Replace the native Apple adapter with @capawesome/capacitor-apple-sign-in 0.1.4, map its ID token into the existing response shape, request email/name scopes, and classify its typed cancellation error. Consumers of both the new and legacy Apple entry points must replace the old native dependency and sync/rebuild their native apps. The web flow remains a Firebase popup. Document the guard's scope: direct Firebase operations and other tabs must be coordinated by the application.

Validation: 1,073 kit tests passed, including cross-provider concurrency and hook-cleanup regression cases; monorepo lint, production kit build, and packed-consumer optional-peer/type compatibility checks. The five consuming apps are being updated to the published release and validated separately.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +47 to +49
assertCurrentUser(auth, expectedUser);
if (mode.mode === 'new') {
const { user } = await signInWithCredential(auth, credential);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 同時ログインで別の利用者のセッションが上書きされる

利用者のログイン状態は確認された(assertCurrentUser)直後から認証完了まで保護されず、その間の別ログインを古い要求が上書きします。
Impact: ログインが重なると、最後に操作した利用者とは異なるアカウントが有効になり得ます。

確認と非同期認証の間に競合区間が残る

applyOAuthCredential は現在の利用者を同期確認した後、認証処理を await します。mode: 'new' では、確認直後に別のログインが完了しても、先に始まった signInWithCredential が後からセッションを置き換えます。処理後の確認では、置き換え後の利用者と認証結果が一致するため競合を検出できません。

linkcredential でも、確認後のセッション変更を検出する前に、捕捉済みの利用者へ認証方法を追加できます。後続確認では既存の変更を取り消せません。Google のネイティブ経路にも同じ競合区間があります。

認証操作を直列化するか、処理中のセッション世代変更を監視する必要があります。変更された要求が認証状態やアカウント連携を確定できない設計にしてください。

Prompt for agents
projects/kit/auth-firebase/internal/src/kit-oauth.ts の applyOAuthCredential と projects/kit/auth-firebase/google/src/kit-google.ts のネイティブ認証経路を確認してください。現在は assertCurrentUser の直後に非同期の Firebase 認証操作を開始するため、その操作中に別の認証要求がセッションを変更すると、古い要求が新しいセッションを上書きしたり、捕捉済みユーザーへ認証方法を追加したりできます。処理後の参照一致では、既に起きた変更を検出または取消できません。認証要求の直列化、セッション世代の追跡、または競合した操作を確定させない仕組みを設計し、new、link、credential、reauthenticate の各モードと全プロバイダーを対象に競合テストを追加してください。
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@rdlabo rdlabo changed the title fix(kit): isolate social providers and guard authentication sessions fix(kit): isolate social auth and migrate Apple to Capawesome Sep 7, 2026
@rdlabo
rdlabo merged commit 80cfe06 into main Sep 7, 2026
14 checks passed
@rdlabo
rdlabo deleted the fix/social-auth-boundaries branch September 7, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant