Skip to content

Conversation

calebbourg
Copy link
Collaborator

@calebbourg calebbourg commented Aug 15, 2025

Description

This PR updates our Session configuration to use with_always_save(true)

From the docs

Configures whether unmodified session should be saved on read or not. When the value is true, the session will be saved even if it was not changed.

This is useful when you want to reset Session expiration time on any valid request at the cost of higher SessionStore write activity and transmitting set-cookie header with each response.

It makes sense to use this setting with relative session expiration values, such as Expiry::OnInactivity(Duration). This setting will not cause session id to be cycled on save.

The default value is false.

GitHub Issue: [Fixes] #179

Changes

  • Use with_always_save(true)

Testing Strategy

I tested this locally by changing the expiry to 1 minute and:

  • confirmed that I was logged out after 1 minute of inactivity.
  • confirmed that I was not logged out after 1 minute while using the application

Concerns

It's not clear why with_always_save(true) works and save() didn't. I didn't look too deeply. My guess is save() bypasses updating the relevant internals of the session data structure.

@calebbourg calebbourg added this to the 1.0.0-beta2 milestone Aug 15, 2025
@calebbourg calebbourg requested a review from jhodapp August 15, 2025 13:02
@calebbourg calebbourg self-assigned this Aug 15, 2025
@calebbourg calebbourg added the bug fix Contains a fix to a known bug label Aug 15, 2025
Copy link
Member

@jhodapp jhodapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice find/fix! Just one requested change inline.

web/src/lib.rs Outdated
.with_secure(app_state.config.is_production())
.with_same_site(tower_sessions::cookie::SameSite::Lax) // Assists in CSRF protection
.with_expiry(Expiry::OnInactivity(Duration::days(1)));
.with_expiry(Expiry::OnInactivity(Duration::days(1)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add this as a new AppState Config variable that we could set on the command line or env var? The default should still be 1 day which means we won't need to change our entrypoint.sh flags when it starts up refactor_platform_rs, nor set an env var in GitHub.

@calebbourg
Copy link
Collaborator Author

calebbourg commented Aug 15, 2025

@jhodapp updated 7a8bb3e
I set it to use seconds so that we can change to minutes or seconds on the fly if we need to.

Copy link
Member

@jhodapp jhodapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Feel free to merge and deploy after fixing the cargo fmt issue.

# API version to use between frontend and backend
BACKEND_API_VERSION=${{ vars.BACKEND_API_VERSION }}
# Session expiry duration in seconds (default: 24 hours = 86400 seconds)
BACKEND_SESSION_EXPIRY_SECONDS=${{ vars.BACKEND_SESSION_EXPIRY_SECONDS }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, going above and beyond!

- 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>
@calebbourg calebbourg force-pushed the 179-renew-sessions-for-active-users branch from 7a8bb3e to a9e91ac Compare August 15, 2025 16:06
@calebbourg calebbourg merged commit 4942591 into main Aug 15, 2025
5 checks passed
@calebbourg calebbourg deleted the 179-renew-sessions-for-active-users branch August 15, 2025 16:17
@github-project-automation github-project-automation bot moved this from Review to ✅ Done in Refactor Coaching Platform Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Contains a fix to a known bug
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants