UUID Use Case

UUID Session Token

A session token is an opaque handle. A v4 UUID identifies the session; the actual user state lives in your store, keyed by that UUID.

Opaque handleServer-side statev4

Generated locally with the Web Crypto API — nothing leaves your browser.

What Is UUID Session Token?

How to generate

  1. On login, mint a v4 UUID and store the session server-side.
  2. Set it as an HttpOnly, Secure, SameSite cookie.
  3. Delete the server-side record on logout.

Use Cases

Code Examples

JavaScript
const sid = crypto.randomUUID();
sessionStore.set(sid, { userId });
res.cookie('sid', sid, { httpOnly: true, secure: true });

Frequently Asked Questions

Why not store data inside the UUID?
A UUID is random; it cannot carry state. Keep state server-side and use the UUID purely as a key.
v4 or v7 for sessions?
v4 — you do not want tokens to be time-guessable or enumerable.

Related tools