diff --git a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java index 61ad59c..562ed51 100644 --- a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java +++ b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java @@ -97,6 +97,11 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { } else { userTokenService.deleteToken(userToken.getUserName()); TokenCacheUtil.evictSingleTokenValue(userToken.getTokenContent()); + response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE); + response.setStatus(440); + response.getWriter().write("Token authentication error: Token has expired"); + logger.warn("Token authentication error: Token has expired"); + return; } } diff --git a/chatto/src/main/resources/static/js/chat.js b/chatto/src/main/resources/static/js/chat.js index cdbaab9..23428b6 100644 --- a/chatto/src/main/resources/static/js/chat.js +++ b/chatto/src/main/resources/static/js/chat.js @@ -330,6 +330,7 @@ async function getAllMessages(toUser) { method: 'GET', headers: headers }); + console.log(response); let data = await response.json(); return data; } @@ -342,6 +343,12 @@ async function getNewMessages(toUser, lastMessageTimeStamp) { method: 'GET', headers: headers }); + console.log(response); + if(response.status == 440) + { + window.alert('Token has expired. Please login again'); + return; + } let data = await response.json(); return data; }