OAuth and sessions¶
Sign in with X uses OAuth 2.0 PKCE on the API server. The browser never stores X access tokens in localStorage — only an httpOnly session cookie.
Flow¶
Browser API server X
| GET /api/auth/x/start | |
|------------------------>| redirect authorize |
|<------------------------|------------------------>|
| callback ?code=… | token exchange |
|------------------------>| store tokens in DB |
| Set-Cookie ix_session | |
|<------------------------| |
GET /api/auth/x/start— creates PKCE verifier/challenge, stores state inoauth_states, redirects to X authorize URL.User approves on X.
GET /api/auth/x/callback— validates state, exchanges code, upsertsx_sessions, sets cookie, redirects toFRONTEND_URL.GET /api/auth/me— returns{ signedIn, user? }from cookie session.POST /api/auth/logout— clears session row + cookie.
Environment¶
Variable |
Purpose |
|---|---|
|
OAuth app client id |
|
Client secret |
|
Must match X developer portal (e.g. |
|
Post-login redirect (e.g. |
|
HMAC signing secret (≥16 chars; required in production) |
Without IFIXEDX_SESSION_SECRET in production, sign-in cannot complete (signing throws).
Token storage¶
Table/collection: x_sessions in ifixedx_local (RxDB on server uses SQLite or in-memory depending on deployment — see server DB bootstrap in server/index.ts).
Tokens are used server-side for:
GET /api/x/meGET /api/x/home-timelineGET /api/x/recent-search
Client behavior¶
fetchusescredentials: "include"for API callsAccount page shows sign-in / sign-out
Live timeline requires signed-in session
Production checklist¶
See OAuth in production.