@@ -69,6 +69,11 @@ public class UserController {
6969 @ Value ("${findfirst.upload.allowed-types}" )
7070 private String [] allowedTypes ;
7171
72+ // Webkit has some issues with local development where localhost
73+ // can't be a secure cookie. - https://bugs.webkit.org/show_bug.cgi?id=218980
74+ @ Value ("${findfirst.secure-cookies:true}" )
75+ private boolean secure ;
76+
7277 @ PostMapping ("/signup" )
7378 public ResponseEntity <String > registerUser (@ Valid @ RequestBody SignupRequest signUpRequest ) {
7479 User user ;
@@ -146,7 +151,7 @@ public ResponseEntity<TokenRefreshResponse> token(
146151 return ResponseEntity .badRequest ().body (new TokenRefreshResponse (null , null , e .toString ()));
147152 }
148153
149- ResponseCookie cookie = ResponseCookie .from ("findfirst" , tkns .jwt ()).secure (true ).path ("/" )
154+ ResponseCookie cookie = ResponseCookie .from ("findfirst" , tkns .jwt ()).secure (secure ).path ("/" )
150155 .domain (domain ).httpOnly (true ).build ();
151156
152157 return ResponseEntity .ok ().header (HttpHeaders .SET_COOKIE , cookie .toString ())
@@ -160,7 +165,7 @@ public ResponseEntity<String> refreshToken(
160165 return refreshTokenService .findByToken (jwt ).map (refreshTokenService ::verifyExpiration )
161166 .map (RefreshToken ::getUser ).map (user -> {
162167 String token = userService .generateTokenFromUser (user .getId ());
163- ResponseCookie cookie = ResponseCookie .from ("findfirst" , token ).secure (true )
168+ ResponseCookie cookie = ResponseCookie .from ("findfirst" , token ).secure (secure )
164169 .sameSite ("strict" ).path ("/" ).domain (domain ).httpOnly (true ).build ();
165170 return ResponseEntity .ok ().header (HttpHeaders .SET_COOKIE , cookie .toString ()).body (token );
166171 }).orElseThrow (() -> new TokenRefreshException (jwt , "Refresh token is not in database!" ));
0 commit comments