LM-03
Sessions
LM-03Sessions
A session is a 60-second token and a row you can delete.
Latch keeps the long-lived part on the server and hands the browser a token that expires in a minute. Rotation is silent, revocation is one call, and every token says exactly who is behind it.
- Title
- Sessions
- Doc. no.
- LM-03
- Rev.
- 04
- Issued
- Nov 2026
- Sheet
- 3 of 4
1.0Lifecycle
Ten minutes in the life of a session.
A session lives for days; the token that proves it lives for 60 seconds and is replaced before it runs out. Drag the cursor along the drawing, or jump to a numbered event, and the readout tells you what a request would get at that second.
Session sess_7k2mq9xw4dines@palletline.io
- Since sign-in
- 1:58
- Session
- Active
- Token in use
- T3
- Expires in
4242 s- Assurance
- aal 1
- A request gets
- 200 OK
0:00 Issue Ines signs in with a passkey. Latch creates the session, which may live up to 7 days, and issues token 1, valid for 60 seconds.
0:50 Rotate Ten seconds before expiry the SDK swaps token 1 for token 2 in the background. Your code never sees the swap, and the old token is never refreshed again.
3:25 Replay refused A copy of token 2, lifted from a log file, is replayed from 203.0.113.7. It expired at 1:50. Latch answers 401 without a lookup: the expiry is in the token.
5:20 Step-up Ines opens payout settings and confirms with her passkey. A token is issued out of turn, carrying aal 2 for the next ten minutes.
7:20 Revoke Her phone is stolen; she revokes the laptop session from it. The token already out stays valid until it expires, never more than 60 seconds.
7:50 Signed out The SDK's next refresh is refused. The tab shows the sign-in screen and every later request gets 401. Strict mode closes the window to zero for one network call.
Devices
2.0Devices
A row per device, and the button that ends it.
Every session carries the facts your users need to recognise it: the device, where it signed in, with what, and when it last checked in. Select a row for the full record; revoking it takes effect at that device's next token check.
Where you are signed in
ines@palletline.io
- MacBook ProLisbon, PT · 12 s ago
- iPhone 16Lisbon, PT · 12 min ago
- iPad AirPorto, PT · Yesterday
- Linux, headlessFrankfurt, DE · 3 min ago
Use the arrow keys to move through the list. A session with no activity for 7 days ends on its own.
Linux, headless
Flagged- Session
- sess_c5n2hr8w3e
- Client
- curl 8.11
- Signed in with
- Email code
- Started
- 18 Nov, 09:31
- Token rotated
- 3 min ago
- Address
- 45.88.97.112
- Place
- Frankfurt, DE
- Assurance
- aal 1
Impossible travel: Lisbon to Frankfurt in 17 minutes, from a hosting provider's address.
"use server";import { latch } from "@latch/nextjs/server";export async function revokeSession() { await latch.sessions.revoke("sess_c5n2hr8w3e");}- Nothing yet. Revoke a session to see the event Latch posts to your endpoint.
3.0Impersonation
See what your customer sees, on the record.
Support staff can open a customer's account as that customer, for a stated reason and a fixed time. The token says who is really at the keyboard, the riskiest actions stay locked, and every click lands in the audit trail under both names.
Ines Carvalho
ines@palletline.io · Palletline · Dispatcher
- Empty. Start a session on the left; each step is written here as it happens.
{ "sub": "usr_9a1c7e33b0", "org_role": "support", "perms": ["users:read", "users:impersonate"], "aal": 2}- Who may start one
- Role with users:impersonate
- Reason
- Required, stored
- Longest session
- 60 min
- Locked actions
- Email, password, passkeys, MFA
- Customer notified
- Optional, by email
4.0Limits
Limits you can read before you hit them.
Every limit is per environment, keyed the way an attacker would least like it, and answered with a 429 and a Retry-After header. Anomaly rules run on every sign-in and token refresh; each can be switched to log only.
4.1Rate limits
| Endpoint | Limit | Window | Keyed by | Over the limit |
|---|---|---|---|---|
| Sign-in attempts | 10 | 15 min | account | 429, then a 15-minute lock |
| Sign-in attempts | 60 | 1 min | IP and /24 | 429 and a proof-of-work challenge |
| Email codes sent | 5 | 1 hour | address | 429; the last code stays valid |
| Code verification | 5 | per code | code | Code burned, a new one required |
| Token refresh | 4 | 1 min | session | 429; the session keeps its token |
| Backend API | 1,000 | 1 s | secret key | 429; 100 a second on Pro |
Sign-in attempts
- Limit
- 10
- Window
- 15 min
- Keyed by
- account
- Over the limit
- 429, then a 15-minute lock
Sign-in attempts
- Limit
- 60
- Window
- 1 min
- Keyed by
- IP and /24
- Over the limit
- 429 and a proof-of-work challenge
Email codes sent
- Limit
- 5
- Window
- 1 hour
- Keyed by
- address
- Over the limit
- 429; the last code stays valid
Code verification
- Limit
- 5
- Window
- per code
- Keyed by
- code
- Over the limit
- Code burned, a new one required
Token refresh
- Limit
- 4
- Window
- 1 min
- Keyed by
- session
- Over the limit
- 429; the session keeps its token
Backend API
- Limit
- 1,000
- Window
- 1 s
- Keyed by
- secret key
- Over the limit
- 429; 100 a second on Pro
4.2Anomaly rules
| Rule | Fires when | Default action | Plans |
|---|---|---|---|
| Impossible travel | Two places further apart than 900 km/h allows | Require a second factor | Pro |
| New country | First sign-in from a country for this user | Email the user | All |
| Hosting provider | IP belongs to a cloud or VPN range | Challenge, then allow | All |
| Token reuse | A refresh token is presented twice | Revoke the whole session | All |
| Device change | User agent family changes mid-session | Revoke the session | Business |
| Burst of failures | 20 failed codes across accounts from one IP | Block the IP for 1 hour | All |
Impossible travel
- Fires when
- Two places further apart than 900 km/h allows
- Default action
- Require a second factor
- Plans
- Pro
New country
- Fires when
- First sign-in from a country for this user
- Default action
- Email the user
- Plans
- All
Hosting provider
- Fires when
- IP belongs to a cloud or VPN range
- Default action
- Challenge, then allow
- Plans
- All
Token reuse
- Fires when
- A refresh token is presented twice
- Default action
- Revoke the whole session
- Plans
- All
Device change
- Fires when
- User agent family changes mid-session
- Default action
- Revoke the session
- Plans
- Business
Burst of failures
- Fires when
- 20 failed codes across accounts from one IP
- Default action
- Block the IP for 1 hour
- Plans
- All
Token anatomy
5.0Token anatomy
Read a session token, line by line.
A Latch token is a signed JWT. Your backend verifies it with a public key it fetched once, so a check costs no network call. Hover a claim to find its explanation, or the other way round.
eyJhbGciOiJFZERTQSIsImtpZCI6Imluc18yMDI2XzExIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2F1dGgucGFsbGV0bGluZS5pbyIsInN1YiI6InVzcl8yZjhjNDFkMDdhIiwic2lkIjoic2Vzc183azJtcTl4dzRkIiwiYXpwIjoiaHR0cHM6Ly9hcHAucGFsbGV0bGluZS5pbyIsIm9yZ19pZCI6Im9yZ19wYWxsZXRsaW5lIiwib3JnX3JvbGUiOiJkaXNwYXRjaGVyIiwicGVybXMiOlsic2hpcG1lbnRzOnJlYWQiLCJzaGlwbWVudHM6c2lnbiJdLCJhYWwiOjIsImlhdCI6MTc5NDk5MzI0MCwiZXhwIjoxNzk0OTkzMzAwLCJqdGkiOiJ0b2tfOXhxMm00azdjMSJ9.JhY5LE3K0-Zh71gX5maqBiNo8SZkMyGRr8sHLk1KrLAMQiGXoFH5Mq1b7ABXX4ZvsQJIKu4r5EI8FO-6DmqxQw
Header, decoded
{ "alg": "EdDSA", "kid": "ins_2026_11", "typ": "JWT"}Payload, decoded
{ "iss": "https://auth.palletline.io", "sub": "usr_2f8c41d07a", "sid": "sess_7k2mq9xw4d", "azp": "https://app.palletline.io", "org_id": "org_palletline", "org_role": "dispatcher", "perms": ["shipments:read", "shipments:sign"], "aal": 2, "iat": 1794993240, "exp": 1794993300, "jti": "tok_9xq2m4k7c1"}Segments
Header Base64url of the first block: how to check the signature.
Payload Base64url of the claims. Encoded, not encrypted.
Signature 64 bytes over header and payload. Change one character above and it no longer matches.
Claims
alg Ed25519 signatures: small, fast to verify and with no padding modes to get wrong.
kid Which signing key was used. Keys rotate every 90 days and the old one is still served for 24 hours, so no token is ever orphaned.
iss Your Latch domain. A token minted for another app fails here, even if its signature is valid.
sub The user. Stable for life, never an email address, so renaming an account breaks nothing.
sid The session this token belongs to: the row in Fig. 2.1. Revoking the session stops its next refresh.
azp The origin allowed to use the token. A token copied into another site's requests is refused.
org_id, org_role The active organization and the member's role in it. Switching organizations issues a new token.
perms Permissions resolved at issue time, so
latch.can()answers from the token without a lookup.aal Assurance level: 2 after a second factor or a passkey with user verification. Step-up checks read this.
iat, exp Issued and expires, sixty seconds apart. Verifiers allow five seconds of clock skew and no more.
import { verifyToken } from "@latch/nextjs/server";const claims = await verifyToken(token, { authorizedParties: ["https://app.palletline.io"], requireAal: 2, // only for routes behind step-up});6.0
Get started
6.0Get started
Short tokens, long sessions, one revoke call.
Sessions, rotation and the device list come with every plan. Impersonation and strict revocation arrive with Business, for teams whose support staff need to see what a customer sees.
npm install @latch/nextjsSessions, by plan
- Token lifetime
- 60 s, all plans
- Session lifetime
- 1 h to 90 days
- Device list
- All plans
- Anomaly rules
- 4 on Free, 6 on Business
- Impersonation
- Business