Ten small apps, one per supported setup and one written with Effect, all
signing in against DummyJSON's auth API.
The nine web apps share the same pages: /login, prefilled with DummyJSON's
test user, and a protected / that shows the user, calls auth/me with the
access token, and signs out. The Expo app has the same sign-in screen, and
splits the protected part into a home screen and a /profile screen that
calls auth/me, so a deep link has somewhere to go.
| App | Setup | User comes from |
|---|---|---|
tanstack-router |
TanStack Router, file-based routes | Login response |
tanstack-start-spa |
TanStack Start in SPA mode | Access token |
tanstack-start-spa-effetch |
TanStack Start in SPA mode, written with Effect | Access token |
tanstack-start-ssr |
TanStack Start with server rendering | Login response |
react-router-declarative |
React Router, <BrowserRouter> |
Login response |
react-router-data |
React Router, createBrowserRouter |
Access token |
react-router-framework-spa |
React Router framework mode with ssr: false |
Login response |
react-router-framework-ssr |
React Router framework mode with server rendering | Login response |
next-app |
Next.js App Router with Proxy | Login response |
expo-router |
Expo Router on iOS and Android (Expo SDK 58) | Login response |
From the repository root, build the package once, then start an app:
pnpm install
pnpm run build
pnpm --dir examples/tanstack-router run devThe apps use the package from this repository, so rebuild it after changing
src. pnpm run build:examples builds the package and every app, which is
what CI checks.
The Expo app runs in Expo Go or a development build:
pnpm --dir examples/expo-router run startOpen a deep link with sessionkit://profile in a development build, or
exp://<host>:8081/--/profile in Expo Go. pnpm --dir examples/expo-router run ios and run android build it natively. In CI it is only bundled, with
expo export --platform ios --platform android.
auth.ts: the DummyJSON client. Its refresh callback maps both 401 and 403 tonull, because DummyJSON answers 403 for an invalid refresh token. Tokens last one minute, so the early refresh runs after about 30 seconds. Requests omitcredentials: "include", which DummyJSON's own snippets use, because session-kit keeps tokens out of cookies.- Guards:
requireSession,redirectIfSignedInandSessionOutletfor TanStack Router and Start.SessionOutletalone in React Router's declarative mode.requireSessionLoader,redirectIfSignedInLoader,SessionOutletanduseAuthRevalidationin data and framework mode. - TanStack Start sets
defaultSsr: falseinsrc/start.ts. Start's own server still renders requests in SPA mode, and the guards need the browser's saved session. - TanStack Start with Effect is the SPA app written with Effect,
effetch and
effetch-query, laid out as
the guide is.
src/backend.tsdescribes DummyJSON with Effect Schemas,src/refresh.tsrefreshes through effetch, andsrc/auth.tsreads the user from the access token.src/api.tsis the API client, a service whosesessionBearerplugin sends the access token, andsrc/runtime.tscomposes the app's layers into one runtime.src/endpoints.tsdeclares the sign-in mutation and the profile query, whichsrc/ui.tsxuses withuseMutationanduseQuery, and the root route gives each session its own query cache. The hooks and the guards are the SPA app's. See the guide. - TanStack Start with server rendering keeps the session in an encrypted
httpOnlycookie withcreateServerAuth(src/auth/server.ts), signs in with DummyJSON from a server function, and refreshes in request middleware (src/start.ts).createMirrorAuthgives the routes and components a client, filled byloadSessionon the server andconnectSessionin the browser. The browser signs out and gets the access token through the session route (src/routes/api/session.ts).auth/meis called both from a server function and, withclientCredentials, from the browser. SetSESSION_SECRET(32 or more random characters) to runvite preview;vite devuses a development secret. The cookie isSecureoutsidevite dev, which Safari refuses overhttp://localhost: tryvite previewin another browser. See the guide. - Next.js keeps the session the same way: Proxy refreshes it
(
proxy.ts), Server Components read it throughlib/auth/session.ts, and a Server Function inapp/actions.tssigns in.useMirrorAuthinapp/providers.tsxgives Client Components the client and renders the page again when the session changes in the browser, so the pages' redirects run. The browser reads the session, signs out and gets the access token through the session route (app/api/session/route.ts).SESSION_SECRETand Safari work as for TanStack Start, withnext startandnext dev. See the guide. - React Router with server rendering keeps the session the same way.
The root route's
sessionMiddlewaregives each request a cookie jar and refreshes, the root loader reads the session, and the sign-in route's action signs in with a plain form that works before scripts load.useMirrorAuthinapp/root.tsxgives the components the client and runs the loaders again when the session changes in the browser, so the protected route'srequireSessionguard redirects. The browser reads the session, signs out and gets the access token through the session route inapp/routes/auth.session.ts.SESSION_SECRETand Safari work as for TanStack Start, withpnpm start(afterpnpm build) andreact-router dev. See the guide. - Expo Router saves the session with
secureStorage().SessionGateinapp/_layout.tsxholds the splash screen, showssrc/unavailable.tsxafter a failed refresh, and re-checks the session when the app returns to the foreground.Stack.Protectedguards the screens, andapp/+native-intent.tsxkeeps a deep link for after the sign-in. Theexpo-secure-storeconfig plugin keeps the session out of Android backups.
Each app is self-contained, so it can be copied out on its own. That is why
the client-side web apps have the same ui.tsx, apart from where the hooks
come from, rather than sharing one. The
server-rendered apps have their own, since they sign in on the server, and so
does the Effect app, whose handlers run Effects. The apps differ in where the
user comes from on purpose, so both user sources appear: the login response,
validated by a schema, or the access token's claims, read with
fromAccessToken. DummyJSON supports both.
DummyJSON has no logout endpoint, so the apps do not pass revoke. Its refresh
tokens stay valid after rotation, so it cannot show the cross-tab rotation race
that session-kit's tests cover. CI never calls DummyJSON: builds don't run the apps,
and the build job blocks the host to make sure.