Skip to content

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

Sessionaal 2×
TokensT1T2T3T4T5T6T7T8T9T10
Requestsreplayed T2 → 401
Since sign-in
1:58
Session
Active
Token in use
T3
Expires in
42 s
Assurance
aal 1
A request gets
200 OK
Fig. 1.1The session of ines@palletline.io from sign-in to revocation. Each bar on the token row is one 60-second token.
  1. 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.

  2. 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. 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.

  4. 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.

  5. 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.

  6. 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.

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.

app.palletline.io/settings/security

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.

Fig. 2.1The security page your users get, with the record behind each row. Revoke one session or all others; the listing shows the call you would make.
app/settings/security/actions.ts
"use server";import { latch } from "@latch/nextjs/server";export async function revokeSession() {  await latch.sessions.revoke("sess_c5n2hr8w3e");}
Your webhook receives
  1. 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.

support.palletline.io/users/usr_2f8c41d07a

Ines Carvalho

ines@palletline.io · Palletline · Dispatcher

Stored with the session and shown in the customer's security log.

Ends after
Fig. 3.1Tomás from Palletline support opens Ines's account for ticket 4821. Start a session, try the actions, end it.
Audit trail0 events
  1. Empty. Start a session on the left; each step is written here as it happens.
Token claimsAgent
{  "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

Rate limits by endpoint, window and key
EndpointLimitWindowKeyed byOver the limit
Sign-in attempts1015 minaccount429, then a 15-minute lock
Sign-in attempts601 minIP and /24429 and a proof-of-work challenge
Email codes sent51 houraddress429; the last code stays valid
Code verification5per codecodeCode burned, a new one required
Token refresh41 minsession429; the session keeps its token
Backend API1,0001 ssecret key429; 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

Anomaly rules, when they fire and what they do by default
RuleFires whenDefault actionPlans
Impossible travelTwo places further apart than 900 km/h allowsRequire a second factorPro
New countryFirst sign-in from a country for this userEmail the userAll
Hosting providerIP belongs to a cloud or VPN rangeChallenge, then allowAll
Token reuseA refresh token is presented twiceRevoke the whole sessionAll
Device changeUser agent family changes mid-sessionRevoke the sessionBusiness
Burst of failures20 failed codes across accounts from one IPBlock the IP for 1 hourAll
  • 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

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.

Encoded · 519 characters

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"}
Fig. 5.1The token on Ines's laptop after the step-up in Fig. 1.1: encoded at the top, decoded below.

Segments

  1. Header Base64url of the first block: how to check the signature.

  2. Payload Base64url of the claims. Encoded, not encrypted.

  3. Signature 64 bytes over header and payload. Change one character above and it no longer matches.

Claims

  1. alg Ed25519 signatures: small, fast to verify and with no padding modes to get wrong.

  2. 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.

  3. iss Your Latch domain. A token minted for another app fails here, even if its signature is valid.

  4. sub The user. Stable for life, never an email address, so renaming an account breaks nothing.

  5. sid The session this token belongs to: the row in Fig. 2.1. Revoking the session stops its next refresh.

  6. azp The origin allowed to use the token. A token copied into another site's requests is refused.

  7. org_id, org_role The active organization and the member's role in it. Switching organizations issues a new token.

  8. perms Permissions resolved at issue time, so latch.can() answers from the token without a lookup.

  9. aal Assurance level: 2 after a second factor or a passkey with user verification. Step-up checks read this.

  10. iat, exp Issued and expires, sixty seconds apart. Verifiers allow five seconds of clock skew and no more.

Caution
The payload is signed, not encrypted: anyone holding the token can read it. Keep personal data, internal ids you would not publish and anything secret out of custom claims.
lib/verify.ts
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.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/nextjs

Sessions, 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