Skip to content

v8.8.0 — Auto-heal stale admin claims (third + final #store-1210 iteration)

Choose a tag to compare

@CaspianTools CaspianTools released this 28 Apr 12:51
· 162 commits to main since this release

Closes the third (and final) iteration of #store-1210. v8.6.0 fixed the diagnostic (precise toast naming the right command); v8.8.0 fixes the recovery (no command needed at all).

The remaining failure mode after v8.6.0: an admin whose users/{uid}.role was set in Firestore before the syncAdminClaim trigger was deployed. The trigger only fires on new writes, so the claim was never set server-side. Token refresh has nothing to pick up. The v8.6.0 toast told them to redeploy Functions and sign out + in — which doesn't help because no trigger fires for existing docs. The only working remediation was the firebase/seed/sync-admin-claims.mjs CLI script, which violates the "releases must never require consumer hand-edits" rule.

This release adds a server-side self-heal callable ensureAdminClaim that any signed-in user can invoke. It reads users/{caller.uid}.role and mirrors it to a custom claim — never escalates privilege beyond what Firestore already says. The library auto-invokes it from two places:

  • AuthContext proactive refresh — on admin sign-in, if Firestore says admin but the cached token claim is missing, call ensureAdminClaim (sets the claim + force-refreshes the token). Bounded to once per uid so undeployed-Functions consumers don't loop.
  • uploadAdminImage retry — on storage/unauthorized, the v8.6.0 plain token-refresh retry is upgraded to call ensureAdminClaim first when Functions is available. Older v8.6.0 fallback preserved when not.

Net effect: stale-claim cases self-heal silently. The first admin upload after upgrading to v8.8.0 + redeploying Functions just works — no toast, no script.

Consumer action required on upgrade

Auto-heal only kicks in after consumers redeploy caspian-admin:

npm install github:Caspian-Explorer/script-caspian-store#v8.8.0
cd firebase/functions-admin && npm install && cd ../..
firebase deploy --only functions:caspian-admin

After deploying, every existing admin's first sign-in heals automatically. Stores that don't redeploy still see the v8.6.0 toast; the v8.8.0 i18n now names firebase deploy --only functions:caspian-admin (more precise than the previous --only functions) plus the sync-admin-claims.mjs fallback.

functions-admin bumped 0.5.0 → 0.6.0. create-caspian-store sibling republish: not needed (scaffolder CLI surface unchanged).