Skip to content

Commit e885890

Browse files
committed
feat: update session cookie management and JWT expiration
- Increased session cookie max age to 86400 seconds (1 day). - Updated JWT token lifetime to match the new session duration.
1 parent 99aa775 commit e885890

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

aperag/views/auth.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
# --- fastapi-users Implementation ---
3535

36+
COOKIE_MAX_AGE = 86400
37+
3638

3739
class UserManager(BaseUserManager[User, str]):
3840
reset_password_token_secret = "SECRET"
@@ -53,11 +55,11 @@ def parse_id(self, value: any) -> str:
5355

5456

5557
def get_jwt_strategy() -> JWTStrategy:
56-
return JWTStrategy(secret=SECRET, lifetime_seconds=3600)
58+
return JWTStrategy(secret=SECRET, lifetime_seconds=86400)
5759

5860

5961
# Transport methods
60-
cookie_transport = CookieTransport(cookie_name="session", cookie_max_age=3600)
62+
cookie_transport = CookieTransport(cookie_name="session", cookie_max_age=COOKIE_MAX_AGE)
6163

6264
# Authentication backends
6365
cookie_backend = AuthenticationBackend(
@@ -394,7 +396,7 @@ async def login_view(
394396
token = await strategy.write_token(user)
395397

396398
# Set cookie
397-
response.set_cookie(key="session", value=token, max_age=3600, httponly=True, samesite="lax")
399+
response.set_cookie(key="session", value=token, max_age=COOKIE_MAX_AGE, httponly=True, samesite="lax")
398400

399401
return view_models.User(
400402
id=str(user.id),

0 commit comments

Comments
 (0)