fix: log disabled users out and keep them out #34
Loading…
Reference in a new issue
No description provided.
Delete branch "jtk/deactivated-users"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #10 (medium).
Bug: disabling a user only blocked new password and magic-link logins. Their existing sessions and remember-me cookies kept working, because
fetch_current_scope_for_userand the LiveViews' session lookups never looked atstatus. The OIDC callback logged disabled users in too.Fix
UserToken.verify_session_token_query/1only matches active users. Every session lookup goes throughAccounts.get_user_by_session_token/1: the auth plug, remember-me cookies, and the admin LiveViews that readsession["user_token"]. So a disabled user is logged out on their next request.Accounts.update_user_by_admin/2deletes all of a user's tokens when their status changes to disabled (same transaction helper as password changes), and logs the count.Accounts.active?/1beforelog_in_userand shows the same "account has been disabled" flash as the other login paths, with aLogger.warning(user id).Tests: disabled users aren't returned for a session token; disabling deletes tokens, while role changes and invalid updates keep them; the plug refuses a disabled user from both the session and a remember-me cookie. The OIDC branch has no controller test (it needs a signed id_token mock, same gap as #21), but the session filter blocks it on the next request anyway.
Not covered: a LiveView that's already connected stays up until it reconnects, since sessions don't set a
live_socket_idto broadcast a disconnect to.mix precommit: 475 passed, 4 skipped.Review from Nye: APPROVE (posted by Upper Wolfjaw, since Forgejo won't let jfro approve its own PR)
The
verify_session_token_queryfilter onuser.status == "active"is safe: status isNOT NULL DEFAULT 'active'(migration 20250816192636), so no existing user gets logged out.update_user_by_admindeletes tokens only when status changes to disabled, inside a transaction. Password, magic-link and OIDC logins all checkactive?.Non-blocking follow-up (filed separately as low): connected LiveViews aren't disconnected on disable, because log_in_user never puts
:live_socket_idin the session, so the disconnect broadcast in user_auth.ex never fires.