feat(auth): store sign-in sessions on the server
Adds the auth_sessions table and the layer around it: one row per signed-in
device, holding the digest of the cookie that device carries.
This is what the previous scheme could not do at all. The cookie used to be
md5 of the password, so it was valid until the password changed and there was
nothing to revoke: no signing out elsewhere, no list of active devices, no
dropping every session when a password changes. A row per device gives all
three, and the cookie itself becomes 32 random bytes that mean nothing without
the row.
Lifetimes slide from the last visit rather than from the sign-in, so coming
back on day 14 pushes the end to day 44 and only a real month of absence signs
anyone out. Extending is a write, so it happens at most once every five
minutes — measured against last_used_at on the row and not against anything
this process remembers, or a visitor returning after a fortnight would never be
extended. The absolute cap is off by default: switching it on would sign the
most active visitors out every few months, which is exactly what the sliding
window is meant to avoid.
Rotation replaces the secret while the device keeps its row, so a value known
before signing in or before a password change stops working afterwards.
AuthCookieFactory is the only place a sign-in cookie is built, which is how its
flags stop being forgettable: HttpOnly and SameSite=Lax always, Secure
following the scheme of the request. Without "remember me" the cookie is a
session one, but the row expiry is what actually limits the visit — browsers
restore session cookies when reopening tabs.
The manager stays free of HTTP so the lifetime arithmetic is testable without a
request; nothing is wired into the request cycle yet.