Commit 9ea7a0d
fix(web): propagate session invalidation to /api/auth/session
NextAuth's stock /api/auth/session route decodes the JWT and returns
the user record to the client without consulting Sourcebot's database.
Three release-acceptance scenarios depended on the endpoint reporting
"logged out" after invalidation:
- AUTHN-004: replayed cookie after signout.
- AUTHN-006: replayed cookie after user is removed from org.
- AUTHN-011: replayed cookie after user is deleted.
The wrapped auth() at the application layer was already cross-checking
sessionVersion and the User row's existence on every withAuth call, so
protected resources correctly returned 401 in all three cases. But
because /api/auth/session never went through that wrapper, the
endpoint continued to leak a positive "you're signed in" answer.
Two changes close the gap:
1. events.signOut now increments User.sessionVersion before writing
the audit log, mirroring invalidateAllSessionsForUser. This is
what AUTHN-004 specifically needed.
2. The jwt callback now performs a single User.findUnique on every
non-login request, returning null when the row is missing
(AUTHN-011) or sessionVersion has been bumped since the JWT was
minted (AUTHN-004 / AUTHN-006). When the callback returns null,
@auth/core (a) reports the session as logged out from
/api/auth/session, (b) skips the rolling-session cookie refresh,
and (c) clears the cookie from the browser via Set-Cookie.
The same query also batches the existing lazy issuerUrl migration,
so the new check costs one User.findUnique per request (with the
existing accounts findMany folded into the same query, net query
count is unchanged or lower).
With the jwt callback now responsible for the invalidation check, the
duplicate cross-check that lived in the wrapped auth() resolver has
been removed. The wrapper is now just a React cache() boundary around
nextAuthResult.auth().
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 3851c66 commit 9ea7a0d
2 files changed
Lines changed: 58 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
217 | 226 | | |
218 | 227 | | |
219 | 228 | | |
| |||
259 | 268 | | |
260 | 269 | | |
261 | 270 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | 271 | | |
268 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
269 | 278 | | |
270 | | - | |
271 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
272 | 288 | | |
273 | 289 | | |
274 | 290 | | |
275 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
276 | 315 | | |
277 | 316 | | |
278 | 317 | | |
| |||
313 | 352 | | |
314 | 353 | | |
315 | 354 | | |
316 | | - | |
| 355 | + | |
317 | 356 | | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
323 | 364 | | |
324 | 365 | | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
| 366 | + | |
345 | 367 | | |
346 | 368 | | |
347 | 369 | | |
| |||
0 commit comments