Skip to content

feat(kit): separate offline route access from remote auth - #33

Merged
rdlabo merged 7 commits into
mainfrom
feat/offline-auth-guard
Jul 25, 2026
Merged

feat(kit): separate offline route access from remote auth#33
rdlabo merged 7 commits into
mainfrom
feat/offline-auth-guard

Conversation

@rdlabo

@rdlabo rdlabo commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

概要

オフライン時の認証を、期限付きトークンの延長ではなく、共有された none / local / remote のアクセス状態として定義します。Guardだけでなく、SQLite/outbox、HTTP、Realtime、オンライン復帰まで同じ状態境界に従います。

状態と不変条件

mode local replica / outbox enqueue pull / outbox replay / HTTP / realtime
none 不可 不可
local 不可
remote
  • required、明示logout、HTTP 401/403は必ず none
  • 新しいprotected guard判定を開始した時点で、既存remote能力を即座にnoneへ降格
  • required / confirm確定時は、anonymous fallback待機前に既存local能力も即座に失効
  • 全Guardでrequired / confirmをauthoritative denialとして扱い、既存能力を残さない
  • 補助Guardもleaseを保持し、遅延した旧auth emissionから新identityをclear/redirectしない
  • enforcement有効時の実HTTP/auth-header 401/403はfallbackより先にaccessを失効し、必ずreject
  • 認証基盤への到達不能だけが、検証済みmanifestを使って local へ遷移可能
  • local では optimistic write とoutbox追加を許可するが、送信は行わない
  • リモート復帰は reauthenticate → activate identity → publish remote → resume transport の順序を固定
  • 復帰処理はsingle-flight化し、世代leaseを永続commit直前にも検証
  • logout・別identityへの遷移は古いleaseを即時無効化し、session mutationを直列化してstale commitを防止

変更内容

  • KitAuthAccessService
    • none / local / remote を同期値とObservableで公開
    • Guard・UI・HTTP・Realtimeが共有可能
  • KitAuthRecoveryService
    • availability検知後の再認証をsingle-flightで実行
    • 401/403はアプリ側classifierより先に明示拒否
    • 通信不能はlocalを保持し、予期しないエラーはErrorHandlerへ報告
  • Auth guard
    • 既存の4状態 KitAuthState を維持し、guard入力だけ unavailable を追加
    • onUnavailable で検証済みローカルmanifestを復元
    • onAuthorized / onUnauthenticated は、従来のboolean/UrlTreeに加えて二段階remote activationを返せる
  • Offline runtime
    • getLocalSession() と既存のremote用 getSession() を分離
    • local modeのenqueue/optimistic updateを許可
    • pull/outbox replayはremote sessionが復元されるまで停止
    • coordinatorに activateOfflineSessionprepareRemoteSessionresumeRemoteSession を追加
    • Guardのleaseとcoordinator内のgenerationを合成し、logout/別identityと競合した古いmanifest commitを拒否
  • HTTP
    • enforceAuthAccessMode opt-in時、local/noneでは認証header生成とtransportを実行しない
    • localはstatus 0として外側のoffline read policyへ渡せる
    • noneは401として拒否し、offline interceptorがローカルデータを返さない
  • Realtime
    • requireRemoteAccess opt-in時、local/noneでsocketを閉じ、remote復帰後に再接続
  • README
    • 状態表、二段階activation、lease配線、統一logout手順、interceptor順序、後方互換の採用手順を記載

後方互換

  • KitAuthState は従来の4状態unionのまま
  • 新しいauth hooks、HTTP enforcement、Realtime enforcementは任意
  • OfflineSyncContext.getLocalSession() は任意で、未実装時は既存 getSession() を利用
  • activateSession() は従来どおり一段階APIとして維持
  • 既存アプリは設定変更なしで従来動作。offline auth境界を採用するアプリだけ段階的にopt-in可能

検証

  • npm run lint
  • npx ng test kit --watch=false(35 files / 467 tests)
  • npm run prebuild(全entry point)
  • tsc -p projects/kit/offline/tsconfig.nonstrict-null.json
  • git diff --check

@netlify

netlify Bot commented Jul 25, 2026

Copy link
Copy Markdown

Deploy Preview for rdlabo-ionic-angular-library ready!

Name Link
🔨 Latest commit c36d390
🔍 Latest deploy log https://app.netlify.com/projects/rdlabo-ionic-angular-library/deploys/6a641c48fbef1d0008670b33
😎 Deploy Preview https://deploy-preview-33--rdlabo-ionic-angular-library.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@rdlabo
rdlabo marked this pull request as ready for review July 25, 2026 02:19

@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: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@rdlabo
rdlabo merged commit f4096b3 into main Jul 25, 2026
12 checks passed
@rdlabo
rdlabo deleted the feat/offline-auth-guard branch July 25, 2026 03:13
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