auth-law
Skill2 starsChanged 53 days agoMITView on GitHub
The Atelier Auth Law — production-hardened session architecture (rotating refresh tokens, families, grace window, silent refresh, sliding window) plus the anti-patterns that corrupt auth. Load before designing or touching ANY authentication code.
In this repository28 other files it gives its agents.
- anime-jsSkill
- apple-designSkill
- asset-pipelineSkill
- atelier-bootstrapSkill
- atelier-buildSkill
- atelier-clarifySkill
- atelier-doctorSkill
- atelier-learnSkill
- atelier-planSkill
- atelier-promoteSkill
- atelier-reviewSkill
- atelier-shipSkill
- atelier-statusSkill
- atelier-updateSkill
- clean-code-lawSkill
- deploy-advisorSkill
- design-lawSkill
- docs-siteSkill
- gatewaySkill
- living-graphicsSkill
- loop-engineSkill
- mcp-makerSkill
- principal-mindSkill
- security-lawSkill
- stack-guidesSkill
- structure-lawSkill
- web-3dSkill
- web-qualitySkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
No unexpected bounce to login — ever, on any click or cross-app navigation.
- Very specific: line 41
Every refresh consumes the token and issues a new one.
- Distinctive: line 47
Golden rule: ONE refresh in flight per app: Every trigger (one-shot timer ~2min before expiry, 401 recovery, tab focus, layout mount) …
- Distinctive: line 56
Every login/refresh writes an activity log (device, IP) — Google-style auditable sessions.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Auth Law
Distilled from a production system that was broken repeatedly by well-meaning "improvements" and then hardened. If you are about to "improve" auth, your improvement is probably in the anti-pattern list. A genuinely logged-in user must NEVER be bounced to login by normal use.
This law covers session/token architecture only. Injection, XSS, CSRF, tenant isolation, rate limiting, and everything else a request path needs is [[security-law]] — load both for any auth-adjacent endpoint.
The six guarantees
- No unexpected bounce to login — ever, on any click or cross-app navigation.
- Token expiry is invisible: new access tokens issue silently.
- No polling. One-shot self-rescheduling timer + on-demand refresh only.
- Auth-layer-first: silent refresh → session check → only then redirect.
- Long sessions survive: multi-hour live streams / videos never drop.
- Sliding window: any visit within 30 days extends 30 days; only true inactivity forces re-login.
Token model
| Thing | Lifetime | Storage |
| Access JWT | 15 min | JS-readable cookie; Authorization: Bearer |
| Refresh token | 30 days, single-use, rotates | HttpOnly cookie + SHA-256 hash in DB |
| Session | 30 days | DB row (truth) + cache |
| expires_at / user cookies | 30 days | JS-readable (schedule timer / routing); not credentials |
Cookie domain .yourdomain.com when multiple subdomains share one session
(central "accounts.*" auth, Google-style) — chosen at intake vs per-app auth.
Rotation, families, grace
Every refresh consumes the token and issues a new one. All tokens from one
login share a token_family_id. A rotated-away token presented outside the
60-second grace window = assumed theft → revoke the family. Inside the
window → return the already-issued successor (absorbs tab races). The grace
window is load-bearing; the single-flight mutex is the real fix.
Golden rule: ONE refresh in flight per app. Every trigger (one-shot timer ~2min before expiry, 401 recovery, tab focus, layout mount) funnels through a single module-level in-flight promise/mutex.
Login flows (all end in the SAME token issuance)
Password (+ optional TOTP 2FA before tokens) · OAuth via state-cookie + JSON
callback into user_identities · Passkeys/WebAuthn in user_passkeys ·
Turnstile/captcha on public forms. Never a parallel session mechanism.
Every login/refresh writes an activity log (device, IP) — Google-style
auditable sessions; owner console can list + revoke sessions per user.
Anti-patterns (each one has actually corrupted production auth)
- ❌ Interval-based refresh polling.
- ❌ A second refresh caller outside the mutex.
- ❌ Two AuthProviders mounted on one route (nested layouts = passthroughs).
- ❌ Zustand/Redux/etc. for auth state — cookies + one AuthContext per app.
- ❌ Redirect to /login on missing access token before silent refresh + session check.
- ❌ Skipping refresh because JS cookies are gone (HttpOnly may still be valid).
- ❌ Family revocation broadened to "revoke all".
- ❌ Shrinking the grace window to "harden" security.
- ❌ Casually changing token lifetimes.
Shipping checklist
- No polling; no unmutexed refresh; one provider per app
- Redirect is the LAST branch; typecheck all affected apps
- OAuth/passkey/2FA terminate in the same issuance
- All four sliding-window scenarios verified
- Sessions auditable + revocable from the console
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

