ADD configurable JWT expiration time in UserController

This commit is contained in:
2025-08-13 23:39:08 +02:00
parent e10335696b
commit 10ebcd5479
2 changed files with 6 additions and 2 deletions

View File

@@ -48,7 +48,7 @@ const Topbar = ({
logout() logout()
.then(() => { .then(() => {
fetchUser(); fetchUser();
navigate(0); navigate("/");
}) })
.catch((error) => { .catch((error) => {
console.error("Logout failed:", error); console.error("Logout failed:", error);

View File

@@ -6,6 +6,7 @@ import com.ddf.vodsystem.entities.User;
import com.ddf.vodsystem.exceptions.NotAuthenticated; import com.ddf.vodsystem.exceptions.NotAuthenticated;
import com.ddf.vodsystem.services.UserService; import com.ddf.vodsystem.services.UserService;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseCookie; import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -17,6 +18,9 @@ import java.util.Optional;
public class UserController { public class UserController {
private final UserService userService; private final UserService userService;
@Value("${jwt.expiration}")
private long jwtExpiration;
public UserController(UserService userService) { public UserController(UserService userService) {
this.userService = userService; this.userService = userService;
} }
@@ -41,7 +45,7 @@ public class UserController {
ResponseCookie cookie = ResponseCookie.from("token", jwt) ResponseCookie cookie = ResponseCookie.from("token", jwt)
.httpOnly(true) .httpOnly(true)
.maxAge(60 * 60 * 24) .maxAge(jwtExpiration / 1000)
.sameSite("None") .sameSite("None")
.secure(true) .secure(true)
.path("/") .path("/")