Skip to content

Commit a9e91ac

Browse files
calebbourgclaude
andcommitted
Add configurable session expiry via BACKEND_SESSION_EXPIRY_SECONDS
- Add backend_session_expiry_seconds field to Config with default 86400 seconds (24 hours) - Update session layer to use config value instead of hardcoded Duration::days(1) - Add BACKEND_SESSION_EXPIRY_SECONDS environment variable to deployment pipeline - Update docker-compose.yaml and entrypoint.sh to pass session expiry parameter - Update .env.local with default session expiry configuration This allows flexible session timeout configuration for different environments while maintaining backward compatibility with 24-hour default. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 35f9e8f commit a9e91ac

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

.github/workflows/deploy_to_do.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ jobs:
9999
BACKEND_SERVICE_API_PATH=${{ vars.BACKEND_SERVICE_API_PATH }}
100100
# API version to use between frontend and backend
101101
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 }}
102104
# Deployment environment used (development, staging, production)
103105
RUST_ENV=${{ vars.RUST_ENV }}
104106

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ services:
7878
BACKEND_API_VERSION: ${BACKEND_API_VERSION}
7979
BACKEND_ALLOWED_ORIGINS: ${BACKEND_ALLOWED_ORIGINS}
8080
BACKEND_LOG_FILTER_LEVEL: ${BACKEND_LOG_FILTER_LEVEL}
81+
BACKEND_SESSION_EXPIRY_SECONDS: ${BACKEND_SESSION_EXPIRY_SECONDS}
8182
TIPTAP_APP_ID: ${TIPTAP_APP_ID}
8283
TIPTAP_URL: ${TIPTAP_URL}
8384
TIPTAP_AUTH_KEY: ${TIPTAP_AUTH_KEY}

entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ main() {
8787
local interface="${BACKEND_INTERFACE:-0.0.0.0}"
8888
local port="${BACKEND_PORT:-4000}"
8989
local origins="${BACKEND_ALLOWED_ORIGINS:-*}"
90+
local session_expiry="${BACKEND_SESSION_EXPIRY_SECONDS:-86400}"
9091

9192
log_info "Starting Refactor Platform API server..."
9293
log_debug "Log level: $log_level, Interface: $interface, Port: $port"
@@ -97,6 +98,7 @@ main() {
9798
-i "$interface" \
9899
-p "$port" \
99100
--allowed-origins="$origins" \
101+
--backend-session-expiry-seconds="$session_expiry" \
100102
"$@"
101103
;;
102104

service/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ pub struct Config {
142142
.map(|s| s.parse::<RustEnv>().unwrap()),
143143
)]
144144
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,
145149
}
146150

147151
impl Default for Config {

web/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ pub async fn init_server(app_state: AppState) -> Result<()> {
5151
// Get non-secure cookies for local testing, while production automatically gets secure cookies
5252
.with_secure(app_state.config.is_production())
5353
.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+
)))
5557
// Save session on every request to reset the inactivity timer
5658
// This ensures active users stay logged in
5759
.with_always_save(true);

0 commit comments

Comments
 (0)