Skip to content

Commit a039d60

Browse files
fix: include userId in logout log, add dev-only warning for JWT secret
Agent-Logs-Url: https://github.com/vitorhugo-java/SpringBoot-JobApplyTracker/sessions/5f1775da-aadb-4d0a-8e9b-d95b9333e860 Co-authored-by: vitorhugo-java <65777252+vitorhugo-java@users.noreply.github.com>
1 parent 8deddc1 commit a039d60

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

backend/src/main/java/com/jobtracker/service/AuthService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515
import org.springframework.security.authentication.BadCredentialsException;
16+
import org.springframework.security.core.Authentication;
17+
import org.springframework.security.core.context.SecurityContextHolder;
1618
import org.springframework.security.core.userdetails.UserDetails;
1719
import org.springframework.security.crypto.password.PasswordEncoder;
1820
import org.springframework.stereotype.Service;
@@ -125,7 +127,9 @@ public MessageResponse resetPassword(ResetPasswordRequest request) {
125127
@Transactional
126128
public MessageResponse logout(LogoutRequest request) {
127129
refreshTokenService.revokeToken(request.refreshToken());
128-
log.info("event=LOGOUT_SUCCESS");
130+
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
131+
String userId = (auth != null && auth.isAuthenticated()) ? auth.getName() : "unknown";
132+
log.info("event=LOGOUT_SUCCESS userId={}", userId);
129133
return new MessageResponse("Logged out successfully");
130134
}
131135

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
SPRING_DATASOURCE_URL: jdbc:mariadb://mariadb:3306/jobtracker?createDatabaseIfNotExist=true&characterEncoding=UTF-8&useUnicode=true
1515
SPRING_DATASOURCE_USERNAME: root
1616
SPRING_DATASOURCE_PASSWORD: root
17+
# WARNING: Replace this secret before any production use. This value is for development only.
1718
JWT_SECRET: ChangeThisToAVeryLongSecretKeyForJWTTokensInDevelopment
1819
CORS_ALLOWED_ORIGINS: "http://localhost:3000,http://localhost:5173"
1920
depends_on:

0 commit comments

Comments
 (0)