Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,31 @@ public ResponseEntity<?> getUserChats(@RequestHeader(value = "Authorization", re
@GetMapping("/chat/session_history")
public ResponseEntity<?> getAnonChatHistory(
@RequestParam String sessionId,
@RequestParam String recipient // This is the username of the dashboard owner
@RequestParam String recipient,
@RequestHeader(value = "Authorization", required = false) String authHeader
) {
;
List<ChatMessageDto> messages = chatService.getChatHistoryForAnonymous(sessionId, recipient);

if (authHeader == null || !authHeader.startsWith("Bearer ")) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.body(Map.of("success", false, "message", "Missing or invalid Authorization header"));
}

String token = authHeader.substring(7);

String username;
try {
username = jwtService.getUsernameFromToken(token);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.body(Map.of("success", false, "message", "Invalid or expired token"));
}

if (!username.equals(recipient)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body(Map.of("success", false, "message", "You are not allowed to access this chat history"));
}

List<ChatMessageDto> messages = chatService.getChatHistoryForAnonymous(sessionId, recipient);
return ResponseEntity.ok(Map.of("success", true, "messages", messages));
}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ security.public-endpoints=\
/ws/,\
/ws/chat,\
/ws/chat/**,\
/api/chat/session_history,\
/api/auth/check-username/**,\
/actuator/health,\
/actuator/info,\
Expand Down