Skip to content

Commit cec6922

Browse files
feat: add the user ID claim to JWT Token
1 parent 52def7d commit cec6922

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

src/main/java/com/vianavitor/simplelibrarygame/controller/auth/AuthenticationController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ResponseEntity<ApiResponse<?>> login(@RequestBody @Valid LoginRequest req
5252
}
5353

5454
user.setLastLogin(LocalDate.now());
55-
repository.save(user);
55+
user = repository.save(user);
5656

5757
String token = tokenService.generateToken(user);
5858
return ResponseEntity.ok(ApiResponse.success(token, "Login successful", req.getRequestURI()));

src/main/java/com/vianavitor/simplelibrarygame/service/auth/TokenService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public String generateToken(User user) throws JWTCreationException {
3333
.withSubject(user.getUsername())
3434
.withExpiresAt(this.getExpireAt())
3535
.withClaim("role", role)
36+
.withClaim("id", user.getId())
3637
.sign(algorithm);
3738
}
3839

0 commit comments

Comments
 (0)