fix: preserve week-long sessions and add profile mascot

This commit is contained in:
Lago committed 2026-10-10 20:40:42 +02:00
1 parent 4e71e9b797
commit 40f24cf5f7
18 files changed
+240 -25

No files matched your search

+3 -3
View File
@@ -279,11 +279,11 @@ max_frequency = "5s"
# 4152127777 = "123456"
# Configure logged in session timeouts.
# [auth.sessions]
[auth.sessions]
# Force log out after the specified duration.
# timebox = "24h"
timebox = "168h"
# Force log out if the user has been inactive longer than the specified duration.
# inactivity_timeout = "8h"
inactivity_timeout = "168h"
# This hook runs before a new user is created and allows developers to reject the request based on the incoming user object.
# [auth.hook.before_user_created]
@@ -0,0 +1,13 @@
do $migration$
declare
definition text;
old_block text := E' else\n update auth.users\n set encrypted_password = extensions.crypt(v_pw, extensions.gen_salt(''bf'')),\n updated_at = now()\n where id = v_uid;\n delete from auth.sessions where user_id = v_uid;\n end if;';
new_block text := E' else\n perform 1 from auth.users where id = v_uid for update;\n if exists (\n select 1 from auth.users\n where id = v_uid\n and encrypted_password is distinct from extensions.crypt(v_pw, encrypted_password)\n ) then\n update auth.users\n set encrypted_password = extensions.crypt(v_pw, extensions.gen_salt(''bf'')),\n updated_at = now()\n where id = v_uid;\n delete from auth.sessions where user_id = v_uid;\n end if;\n end if;';
begin
select pg_get_functiondef('public._ensure_auth_user(text,text,text)'::regprocedure) into definition;
if strpos(definition, old_block) = 0 then
raise exception 'Unexpected _ensure_auth_user password update block';
end if;
execute replace(definition, old_block, new_block);
end;
$migration$;
@@ -0,0 +1,55 @@
begin;
do $test$
declare
fixture_email text := 'session-test-' || gen_random_uuid()::text || '@example.invalid';
fixture_uid uuid;
fixture_session uuid := gen_random_uuid();
previous_hash text;
previous_updated timestamptz;
begin
perform public._ensure_auth_user(fixture_email, 'Session Test', 'session-test-ticket');
select id, encrypted_password, updated_at into fixture_uid, previous_hash, previous_updated
from auth.users where email = fixture_email;
if fixture_uid is null then raise exception 'Fixture user was not created'; end if;
insert into auth.sessions (id, user_id, created_at, updated_at)
values (fixture_session, fixture_uid, now() - interval '6 days', now());
for iteration in 1..3 loop
perform public._ensure_auth_user(fixture_email, 'Session Test', 'session-test-ticket');
end loop;
if not exists (select 1 from auth.sessions where id = fixture_session) then
raise exception 'Unchanged imports revoked an existing session';
end if;
if not exists (select 1 from auth.users where id = fixture_uid
and encrypted_password = previous_hash and updated_at = previous_updated) then
raise exception 'Unchanged imports rewrote the password';
end if;
raise notice 'PASS: repeated unchanged ticket imports preserve session and password';
perform public._ensure_auth_user(fixture_email, 'Session Test', 'session-test-new-ticket');
if exists (select 1 from auth.sessions where id = fixture_session) then
raise exception 'Changed password did not revoke session';
end if;
if not exists (select 1 from auth.users where id = fixture_uid
and encrypted_password = extensions.crypt('session-test-new-ticket', encrypted_password)) then
raise exception 'Changed password was not synchronized';
end if;
raise notice 'PASS: changed ticket password updates hash and revokes session';
fixture_email := 'session-test-' || gen_random_uuid()::text || '@appe.at';
perform public._ensure_auth_user(fixture_email, 'Session Admin Test', 'first-ticket');
select id, encrypted_password into fixture_uid, previous_hash from auth.users where email = fixture_email;
fixture_session := gen_random_uuid();
insert into auth.sessions (id, user_id, created_at, updated_at)
values (fixture_session, fixture_uid, now(), now());
perform public._ensure_auth_user(fixture_email, 'Session Admin Test', 'different-ticket');
if not exists (select 1 from auth.sessions where id = fixture_session) or
not exists (select 1 from auth.users where id = fixture_uid and encrypted_password = previous_hash) then
raise exception 'Admin password session changed during ticket sync';
end if;
raise notice 'PASS: existing admin password and session survive ticket changes';
end;
$test$;
rollback;