feat(examples): add stateful (server-side) sessions example - #16
Merged
Merged
Conversation
…stored server-side
cschetan77
reviewed
Jul 10, 2026
…e in layout - drop unused ts-node dep + dead tsconfig block (tsx/tsc/vitest are used) - use <%= over <%- so the user name is HTML-escaped in the layout
Standalone app example — remove declaration/declarationMap (no library consumers), DOM libs (server-side, no DOM usage), and resolveJsonModule (no JSON imports).
…ions # Conflicts: # .github/workflows/examples.yml # README.md
2 tasks
cschetan77
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new self-contained example,
example-express-stateful-sessions, demonstrating how to use a custom server-side session store with@auth0/auth0-express.By default the SDK is stateless — the whole session is encrypted into the cookie. Passing a
sessionStoretocreateAuth0switches to a stateful session: the session data (authenticated user + tokens) is persisted server-side and the cookie only carries an encrypted reference to it.src/session-store.ts—InMemorySessionStore implements SessionStore<StoreOptions>(aMap), implementingget/set/delete/deleteByLogoutToken. Comments call out that it's illustrative and would be Redis/DB in production.src/index.ts— wires the store viacreateAuth0({ sessionStore })and protects/privatewith the SDK'srequiresAuth().Tests
Follows the existing
example-express-mcdpattern (MSW + supertest):src/session-store.spec.ts— unit-tests the store directly: set/get round-trip, delete, anddeleteByLogoutTokenmatching onsubandsid(plus a non-match leaves sessions intact).src/index.spec.ts— mocks Auth0 discovery, JWKS, and the token endpoint (signing a real RS256 ID token withjose), drives a full mocked login (/auth/login→/auth/callback), and asserts:user.sub), proving the session lives server-side;/private.CI
Adds a
Stateful Sessionsjob to.github/workflows/examples.ymlrunningbuild+test:ci, mirroring the other per-example jobs.Verification
npm run build -w @auth0/auth0-express && npm run build -w example-express-stateful-sessions && npm run test:ci -w example-express-stateful-sessions— build clean, 8/8 tests passing.