diff --git a/crates/storage-pg/src/user/session.rs b/crates/storage-pg/src/user/session.rs index ff91726e..82ea9ca2 100644 --- a/crates/storage-pg/src/user/session.rs +++ b/crates/storage-pg/src/user/session.rs @@ -232,11 +232,13 @@ impl<'c> BrowserSessionRepository for PgBrowserSessionRepository<'c> { r#" SELECT DISTINCT ON (s.user_session_id) s.user_session_id, + s.created_at AS "user_session_created_at", + s.finished_at AS "user_session_finished_at", u.user_id, - u.username, - s.created_at, + u.username AS "user_username", + u.primary_user_email_id AS "user_primary_user_email_id", a.user_session_authentication_id AS "last_authentication_id", - a.created_at AS "last_authd_at", + a.created_at AS "last_authd_at" FROM user_sessions s INNER JOIN users u USING (user_id) diff --git a/crates/storage-pg/src/user/tests.rs b/crates/storage-pg/src/user/tests.rs index 9aec949d..62ea2767 100644 --- a/crates/storage-pg/src/user/tests.rs +++ b/crates/storage-pg/src/user/tests.rs @@ -372,6 +372,16 @@ async fn test_user_session(pool: PgPool) { assert_eq!(repo.browser_session().count_active(&user).await.unwrap(), 1); + // The session should be in the list of active sessions + let session_list = repo + .browser_session() + .list_active_paginated(&user, Pagination::first(10)) + .await + .unwrap(); + assert!(!session_list.has_next_page); + assert_eq!(session_list.edges.len(), 1); + assert_eq!(session_list.edges[0], session); + let session_lookup = repo .browser_session() .lookup(session.id) @@ -392,6 +402,15 @@ async fn test_user_session(pool: PgPool) { // The active session counter is back to 0 assert_eq!(repo.browser_session().count_active(&user).await.unwrap(), 0); + // The session should not be in the list of active sessions anymore + let session_list = repo + .browser_session() + .list_active_paginated(&user, Pagination::first(10)) + .await + .unwrap(); + assert!(!session_list.has_next_page); + assert!(session_list.edges.is_empty()); + // Reload the session let session_lookup = repo .browser_session()