Skip to content

Commit

Permalink
HOTFIX: Add token validation (#73)
Browse files Browse the repository at this point in the history
* fix: solve merge conflicts

* feat: integrate admin login and feedback recap page with backend

* feat: add google calendar popup to daftar jadwal page

* refactor: remove unused feedback dummy data

* hotfix: add token validation
  • Loading branch information
lontonggg authored Aug 5, 2024
1 parent 5404a70 commit 5baf026
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const config = {
MIXPANEL_PROJECT_TOKEN: process.env.REACT_APP_MIXPANEL_PROJECT_TOKEN,
},
production: {
// API_BASE_URL: process.env.REACT_APP_AWS_BACKEND_URL,
API_BASE_URL: "https://stg.api.susunjadwal.cs.ui.ac.id/susunjadwal/api",
API_BASE_URL: process.env.REACT_APP_AWS_BACKEND_URL,
BASE_URL: "/",
},
development: {
Expand Down
2 changes: 2 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Contributors from "containers/Contributors";
import Feedback from "containers/Feedback";
import AdminLogin from "containers/Admin/Login";
import AdminFeedbacks from "containers/Admin/Feedbacks";
import { validateAuth } from "utils/auth";

import withAnalytics from "utils/analytics";

Expand Down Expand Up @@ -105,6 +106,7 @@ function RoutesWithNavbar() {
}

function PrivateRoute({ component: Component, ...rest }) {
validateAuth();
const auth = useSelector((state) => state.auth);

return (
Expand Down
3 changes: 3 additions & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ export const updateReviewStatus = async (token, reviewId, status) =>
headers: { Authorization: `Bearer ${token}` },
},
);

export const validateToken = async () =>
await instance.get("/auth/me");
11 changes: 10 additions & 1 deletion src/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupAxiosInstance } from "services/api";
import { setupAxiosInstance, validateToken } from "services/api";
// import { useMixpanel } from "hooks/useMixpanel";

export function persistAuth(auth) {
Expand Down Expand Up @@ -37,3 +37,12 @@ export function loadCompletion() {
const asJson = JSON.parse(persistedCompletion);
return asJson;
}

export async function validateAuth() {
try{
await validateToken();
} catch (error) {
localStorage.clear();
window.location.replace("/");
}
}

0 comments on commit 5baf026

Please sign in to comment.