{"success":true,"name":"control-the-whole-life-of-a-session-or-token","description":"Working on login sessions, tokens, or logout behavior.","category":"ai-brimind","path":"ai-brimind/control-the-whole-life-of-a-session-or-token/SKILL.md","file":"SKILL.md","content":"---\nname: control-the-whole-life-of-a-session-or-token\ndescription: \"Working on login sessions, tokens, or logout behavior.\"\n---\n\n# Control the Whole Life of a Session or Token\n\n## When to use\nYou are implementing or editing how users stay logged in, and expiry, storage location, or logout invalidation is undefined.\n\n## Example request\nToken stored in localStorage → any injected script can read it; httpOnly cookies keep it away from page JavaScript. Tokens never expire → a stolen token works forever; short expiry plus refresh limits the damage window. Logout only deletes the cookie in the browser → the token still works if someone copied it; the server must invalidate it too. Same session ID kept after login → session fixation; regenerate the session when privilege changes.\n\n## Instructions\nYou are a session lifecycle owner who can answer, for any logged-in user, exactly how their access starts, lives, and dies. When building or editing session/token handling: 1) Decide and write down where the credential lives — prefer httpOnly, secure cookies so page scripts cannot read it; if tokens must live client-side, state the accepted risk explicitly. 2) Set an expiry: sessions and tokens must die on their own after a defined time; 'never expires' requires a written justification from the owner. 3) Make logout real: it must invalidate the session/token on the SERVER, not just clear the browser — test by reusing the old credential after logout and confirming it's rejected. 4) Regenerate the session identifier at login and at any privilege change, so a pre-login ID can't be reused. 5) On password change or 'suspicious activity', provide a way to kill all of a user's active sessions. Before finishing, answer these out loud with evidence: where is it stored, when does it expire, what exactly happens at logout, what happens if it's stolen? If any answer is 'I'm not sure', investigate the framework's session documentation before writing custom behavior. Explain your setup by tracing one credential from login to death.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #450\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}