Rabbinatix
Sign inGet started
Store

Sign out and refresh a session

FreeFlow
@rabbinatix/sign-out-and-refresh-a-session by Rabbinatixupdated Oct 13, 2026

The app swaps its refresh token for a new pair before the session runs out, or signs out; a stolen token used twice ends every session.

Sign up to use it

Keeping people signed in safely, and letting them sign out:

  • Client app refreshes the session when the access token is about to run out, or signs out, and knows when to ask for a new sign-in.
  • Auth service finds the session by a hash of the refresh token (the token itself is never stored), refuses a revoked or expired one, and gives a new access token and a new refresh token (rotation).
  • Session store keeps the sessions. Event bus (optional) receives user.signed_out.

Tricky step: each refresh token works once. When an old one comes back after it was swapped, someone copied it: every session of that user ends, and they sign in again.

Signing out always answers 204, whether or not the token was known, so it can be retried and gives nothing away.

Previewlanes are roles; you pick your systems when importing
Not found401Other
Start in Client app. step 1 of 23. key stepOn Session
Call to another system in Client app. step 2 of 23. key stepCall refresh session
Start in Auth service. step 3 of 23. key stepOn POST /api/v1/sessions/refresh
Resource in Auth service. step 4 of 23. key stepFind the session
Answer in Session store. step 5 of 23. key stepsessions.findByTokenHash
Resource in Auth service. step 6 of 23. key stepEnd every session of the user
Answer in Session store. step 7 of 23. key stepsessions.revokeAllForUser
Return in Auth service. step 8 of 23. key stepStolen token → 401, all sessions end
Return in Auth service. step 9 of 23. key stepEnded session → 401
Resource in Auth service. step 10 of 23. key stepRotate: the old token stops working
Answer in Session store. step 11 of 23. key stepsessions.rotate
Return in Auth service. step 12 of 23. key stepNew pair → 200
Return in Auth service. step 13 of 23. key stepUnknown token → 401
Return in Client app. step 14 of 23. key stepReturn
Return in Client app. step 15 of 23. key stepReturn
Return in Client app. step 16 of 23. key stepReturn
Call to another system in Client app. step 17 of 23. key stepCall sign out
Start in Auth service. step 18 of 23. key stepOn POST /api/v1/sessions/logout
Resource in Auth service. step 19 of 23. key stepEnd the session
Answer in Session store. step 20 of 23. key stepsessions.revoke
Return in Auth service. step 21 of 23. key stepSigned out → 204, known token or not
Return in Client app. step 22 of 23. key stepReturn
Return in Client app. step 23 of 23. key stepReturn
Client app
Web frontend
Auth service
Backend service
Session store
Database

Up and down arrows: previous or next step. Home, End: first or last. Enter: select. Shift F10: more actions.

APIs
POST{base}/sessions/refresh· Swap a refresh token for a new pair
Auth service provides it · Client app calls it
Request body
refreshToken: string
200
accessToken: string
refreshToken: string
expiresIn: integer
401
error: string
POST{base}/sessions/logout· Sign out: end this session
Auth service provides it · Client app calls it
Request body
refreshToken: string
204
Data operations
sessions.findByTokenHashqueryon Session store(tokenHash: string)
sessions.rotateupdateon Session store(id: string, tokenHash: string)
sessions.revokeupdateon Session store(tokenHash: string)
sessions.revokeAllForUserupdateon Session store(userId: string)
Test cases
Refresh before the session runs out→ Still signed in, with a new pair
Refresh after signing out→ Sign in again
Refresh after the session ran out→ Sign in again
Old token used again ends every session→ Sign in again
Unknown refresh token→ Sign in again
Sign out→ Signed out
Signing out publishes user.signed_out→ Signed outwith “Publish user.signed_out”
Requirements
A refresh token works once: each refresh gives a new one.
An old refresh token used again ends every session of that user.
A signed-out, expired or unknown session can’t be refreshed.
Signing out ends the session at once.
Roles (4)
Client app
Keeps the session going and signs out · Web frontend or mobile app
Auth service
Rotates refresh tokens and ends sessions · Backend service
Session store
Database (or cache) with the sessions · Database
Event bus (optional)
Receives user.signed_out (optional) · Queue / event bus
Settings
Access token lifetime (seconds)900
Publish user.signed_outoff
Refresh token fieldrefreshToken (renamable)

Also as a whiteboard

Versions