File tree Expand file tree Collapse file tree 7 files changed +17
-15
lines changed Expand file tree Collapse file tree 7 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 99
99
BACKEND_SERVICE_API_PATH=${{ vars.BACKEND_SERVICE_API_PATH }}
100
100
# API version to use between frontend and backend
101
101
BACKEND_API_VERSION=${{ vars.BACKEND_API_VERSION }}
102
+ # Session expiry duration in seconds (default: 24 hours = 86400 seconds)
103
+ BACKEND_SESSION_EXPIRY_SECONDS=${{ vars.BACKEND_SESSION_EXPIRY_SECONDS }}
102
104
# Deployment environment used (development, staging, production)
103
105
RUST_ENV=${{ vars.RUST_ENV }}
104
106
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ services:
78
78
BACKEND_API_VERSION : ${BACKEND_API_VERSION}
79
79
BACKEND_ALLOWED_ORIGINS : ${BACKEND_ALLOWED_ORIGINS}
80
80
BACKEND_LOG_FILTER_LEVEL : ${BACKEND_LOG_FILTER_LEVEL}
81
+ BACKEND_SESSION_EXPIRY_SECONDS : ${BACKEND_SESSION_EXPIRY_SECONDS}
81
82
TIPTAP_APP_ID : ${TIPTAP_APP_ID}
82
83
TIPTAP_URL : ${TIPTAP_URL}
83
84
TIPTAP_AUTH_KEY : ${TIPTAP_AUTH_KEY}
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ main() {
87
87
local interface=" ${BACKEND_INTERFACE:- 0.0.0.0} "
88
88
local port=" ${BACKEND_PORT:- 4000} "
89
89
local origins=" ${BACKEND_ALLOWED_ORIGINS:-* } "
90
+ local session_expiry=" ${BACKEND_SESSION_EXPIRY_SECONDS:- 86400} "
90
91
91
92
log_info " Starting Refactor Platform API server..."
92
93
log_debug " Log level: $log_level , Interface: $interface , Port: $port "
@@ -97,6 +98,7 @@ main() {
97
98
-i " $interface " \
98
99
-p " $port " \
99
100
--allowed-origins=" $origins " \
101
+ --backend-session-expiry-seconds=" $session_expiry " \
100
102
" $@ "
101
103
;;
102
104
Original file line number Diff line number Diff line change @@ -142,6 +142,10 @@ pub struct Config {
142
142
. map( |s| s. parse:: <RustEnv >( ) . unwrap( ) ) ,
143
143
) ]
144
144
pub runtime_env : RustEnv ,
145
+
146
+ /// Session expiry duration in seconds (default: 24 hours = 86400 seconds)
147
+ #[ arg( long, env, default_value_t = 86400 ) ]
148
+ pub backend_session_expiry_seconds : u64 ,
145
149
}
146
150
147
151
impl Default for Config {
Original file line number Diff line number Diff line change @@ -6,9 +6,6 @@ use axum::{
6
6
} ;
7
7
use axum_login:: AuthSession ;
8
8
use domain:: users;
9
- use log:: * ;
10
- use tower_sessions:: Session ;
11
-
12
9
pub ( crate ) struct AuthenticatedUser ( pub users:: Model ) ;
13
10
14
11
#[ async_trait]
26
23
. await
27
24
. map_err ( |( status, msg) | ( status, msg. to_string ( ) ) ) ?;
28
25
29
- // Touch the session to update activity timestamp for session renewal
30
- if let Ok ( tower_session) = Session :: from_request_parts ( parts, state) . await {
31
- if let Err ( e) = tower_session. save ( ) . await {
32
- warn ! ( "Failed to touch session for activity renewal: {e:?}" ) ;
33
- // Continue with authentication - session touch failure shouldn't block authentication
34
- } else {
35
- trace ! ( "Session touched successfully for activity renewal" ) ;
36
- }
37
- }
38
-
39
26
match session. user {
40
27
Some ( user) => Ok ( AuthenticatedUser ( user) ) ,
41
28
None => Err ( ( StatusCode :: UNAUTHORIZED , "Unauthorized" . to_string ( ) ) ) ,
Original file line number Diff line number Diff line change @@ -51,7 +51,12 @@ pub async fn init_server(app_state: AppState) -> Result<()> {
51
51
// Get non-secure cookies for local testing, while production automatically gets secure cookies
52
52
. with_secure ( app_state. config . is_production ( ) )
53
53
. with_same_site ( tower_sessions:: cookie:: SameSite :: Lax ) // Assists in CSRF protection
54
- . with_expiry ( Expiry :: OnInactivity ( Duration :: days ( 1 ) ) ) ;
54
+ . with_expiry ( Expiry :: OnInactivity ( Duration :: seconds (
55
+ app_state. config . backend_session_expiry_seconds as i64 ,
56
+ ) ) )
57
+ // Save session on every request to reset the inactivity timer
58
+ // This ensures active users stay logged in
59
+ . with_always_save ( true ) ;
55
60
56
61
// Auth service
57
62
let backend = Backend :: new ( & app_state. database_connection ) ;
Original file line number Diff line number Diff line change @@ -493,7 +493,8 @@ mod organization_endpoints_tests {
493
493
494
494
let session_layer = SessionManagerLayer :: new ( session_store)
495
495
. with_secure ( false )
496
- . with_expiry ( Expiry :: OnInactivity ( Duration :: days ( 1 ) ) ) ;
496
+ . with_expiry ( Expiry :: OnInactivity ( Duration :: days ( 1 ) ) )
497
+ . with_always_save ( true ) ;
497
498
498
499
// Auth service
499
500
let backend = Backend :: new ( db) ;
You can’t perform that action at this time.
0 commit comments