fix(auth): 세션 복구가 no-session이면 로그인 버튼을 보인다

문제: useSessionAction이 recover()의 결과를 버린다. owner가
"no-session"을 돌려주고 상태를 recovery-pending으로 두면 보호 라우트와
셸은 계속 "세션 복구" 버튼만 보이고, 로그인으로 갈 길이 없다. owner가
지켜야 할 상태 전이도 어디에도 적혀 있지 않아 owner 작성자가 화면
코드를 읽고 추론해야 했다.

고른 방법: 두 가지를 함께 한다.
- SessionState·SessionGateway.recover·ExternalSessionOwner에 전이
  계약을 적는다. restored면 authenticated, no-session이면
  unauthenticated(또는 integration-failed), reject면 상태 유지.
- SessionProvider가 recover()의 답을 쓴다. no-session을 받았는데
  owner가 아직 recovery-pending이면, owner가 다음에 알릴 때까지 화면에
  unauthenticated로 보인다. 그래서 라우트 문과 셸 모두 로그인 버튼을
  보인다.
버린 대안: 어댑터가 전이를 검사해 throw. 그러면 화면은 "작업 실패"만
보이고 여전히 로그인 버튼이 없다. 어댑터가 상태를 덮어쓰는 것은 구독
알림을 새로 만들어야 해서 scope fence와 얽힌다.

위험·한계: 계약을 어기는 owner의 상태를 화면에서만 바로잡는다.
application·scope fence는 owner의 상태를 그대로 본다.

검증: tests/component/session-recovery.test.tsx 4건(수정 전 2건 실패
확인), router·app-shell·route-status-surfaces·auth-session-adapter
테스트 통과, check:types, eslint 통과.

Refs: docs/reviews/2026-11-03-maturity-review/09-app-core.md 09-11
This commit is contained in:
DongHyeonka
2026-11-04 20:23:22 +09:00
parent 004a205748
commit d7c6cb4fd2
4 changed files with 190 additions and 2 deletions
@@ -1,3 +1,19 @@
/**
* 1103/09-11. The owner of the session moves it; nothing else does.
*
* - `unauthenticated` → `authenticated`: a sign-in completed (after
* `beginSignIn`, often on the page load that returns from the sign-in).
* - `authenticated` → `recovery-pending`: the credential stopped working
* (a server 401, a failed refresh) and the owner can still try to restore it.
* - `authenticated` → `unauthenticated`: `signOut`, or a 401 nothing can
* restore.
* - `recovery-pending` → `authenticated` | `unauthenticated`: a recovery ended,
* the owner's own or `recover()`'s (see there).
* - any → `integration-failed`: the owner cannot work at all.
*
* Every change of state or subject notifies subscribers once, and each one
* fences server state, so a token refresh for the same user changes neither.
*/
export type SessionState =
| "authenticated"
| "unauthenticated"
@@ -27,6 +43,16 @@ export type SessionGateway = Readonly<{
* to keep existing owners working; the transport races the signal either way,
* and a recovery that answers after the request already ended is observed but
* never turned into a user-visible sign-out.
*
* 1103/09-11. The state is moved before the promise settles:
*
* - `"restored"`: the state is `authenticated`, with its subject.
* - `"no-session"`: the state is `unauthenticated` (or
* `integration-failed`). Never `recovery-pending`: the screen would keep
* offering a recovery that already said no. Presentation shows sign-in
* after this answer whatever the owner reports, until it next notifies.
* - rejects: the owner could not tell (network, timeout). The state is left
* as it was, so the user can try again.
*/
recover(
context?: CredentialOperationContext,