fix session cookies and catalog pricing visibility

This commit is contained in:
wlx committed 2026-09-25 23:09:59 +08:00
1 parent 05ed1fc9a4
commit 8a65109c80
9 files changed
+71 -25

No files matched your search

@@ -74,7 +74,9 @@ public class AuthController {
HttpServletResponse response
) {
AuthService.AuthResult result = authService.login(input.account(), input.password(), meta(request));
response.addHeader(HttpHeaders.SET_COOKIE, sessionCookie(result.token(), Duration.ofHours(sessionTtlHours)).toString());
// Keep the browser session cookie ephemeral. The server-side session still
// has its normal TTL, but a closed browser must require a fresh login.
response.addHeader(HttpHeaders.SET_COOKIE, sessionCookie(result.token(), null).toString());
return Map.of("user", result.user());
}
@@ -88,7 +90,7 @@ public class AuthController {
AuthService.AuthResult result = authService.register(
input.invitationCode(), input.account(), input.password(), input.displayName(), meta(request)
);
response.addHeader(HttpHeaders.SET_COOKIE, sessionCookie(result.token(), Duration.ofHours(sessionTtlHours)).toString());
response.addHeader(HttpHeaders.SET_COOKIE, sessionCookie(result.token(), null).toString());
return ResponseEntity.status(HttpStatus.CREATED).body(Map.of("user", result.user()));
}
@@ -155,13 +157,13 @@ public class AuthController {
}
private ResponseCookie sessionCookie(String value, Duration maxAge) {
return ResponseCookie.from(SESSION_COOKIE, value)
var builder = ResponseCookie.from(SESSION_COOKIE, value)
.httpOnly(true)
.secure(secureCookie)
.sameSite("Lax")
.path("/")
.maxAge(maxAge)
.build();
.path("/");
if (maxAge != null) builder.maxAge(maxAge);
return builder.build();
}
public static String sessionToken(HttpServletRequest request) {