diff --git a/frontend/src/App.js b/frontend/src/App.js
index a96b450..119563e 100644
--- a/frontend/src/App.js
+++ b/frontend/src/App.js
@@ -12,7 +12,6 @@ import Verify from "./Components/Verify";
import ContactList from "./Components/contactList";
import SearchUser from "./Components/searchUser";
-
class App extends Component {
constructor(props) {
super(props);
@@ -25,7 +24,14 @@ class App extends Component {
}
async componentDidMount() {
- const basic = AuthService.getBasicInfo();
+ let basic = AuthService.getBasicInfo();
+ if (basic) {
+ await AuthService.validToken(basic.token);
+ basic = AuthService.getBasicInfo();
+ if (!basic) {
+ this.setState({ basic: null, currentUser: null });
+ }
+ }
if (basic) {
await AuthService.getUserDataFromBackend(basic.token, basic.id);
@@ -43,7 +49,7 @@ class App extends Component {
return (
-
+
@@ -56,7 +62,7 @@ class App extends Component {
-
+
diff --git a/frontend/src/Services/AuthService.js b/frontend/src/Services/AuthService.js
index 1f36f80..529d6a0 100644
--- a/frontend/src/Services/AuthService.js
+++ b/frontend/src/Services/AuthService.js
@@ -25,6 +25,17 @@ class AuthService {
}
}
+ async validToken(token) {
+ const response = await axios.post(API_URL + "/jwt/checkExpired", {
+ authToken: token,
+ });
+
+ if (!response.data) {
+ this.logout();
+ alert("Login expired, please login again.");
+ }
+ }
+
async login(username, password) {
const response = await axios.post(API_URL + "/login", {
username,
diff --git a/frontend/src/constant.jsx b/frontend/src/constant.jsx
index 678a6f0..8b1a80b 100644
--- a/frontend/src/constant.jsx
+++ b/frontend/src/constant.jsx
@@ -1,5 +1,5 @@
// url for local
-// export const API_URL = "http://localhost:8080";
+export const API_URL = "http://localhost:8080";
// url for heroku
-export const API_URL = "https://crm-c-and-h-backend.herokuapp.com"
+//export const API_URL = "https://crm-c-and-h-backend.herokuapp.com"