Skip to content

Commit

Permalink
Merge pull request #20 from Aar-if/newaltv1
Browse files Browse the repository at this point in the history
Newaltv1
  • Loading branch information
snehal0904 authored Oct 4, 2023
2 parents c50b1a5 + b581d49 commit b325772
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions packages/student-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,51 +56,51 @@ function App() {
telemetryFactory.init(); //TODO: Enable this when all the telemetry endpoints are set
}, []);

// useEffect(() => {
// // Call checkTokenValidity to start checking immediately after the component is mounted
// checkTokenValidity();
// }, []);
useEffect(() => {
// Call checkTokenValidity to start checking immediately after the component is mounted
checkTokenValidity();
}, []);

// function checkTokenValidity() {
// console.log("INSIDE checkTokenValidity");
// const refreshToken = localStorage.getItem("refreshToken");
// console.log("INSIDE tokenCheckInterval2 ");
// console.log(refreshToken);
// if (Object.keys(refreshToken).length) {
// const interval = 30 * 60 * 1000; // 30 minutes
// // const interval = 2 * 1000; // 2 seconds
function checkTokenValidity() {
console.log("INSIDE checkTokenValidity");
const refreshToken = localStorage.getItem("refreshToken");
console.log("INSIDE tokenCheckInterval2 ");
console.log(refreshToken);
if (refreshToken) {
const interval = 30 * 60 * 1000; // 30 minutes
// const interval = 2 * 1000; // 2 seconds

// const tokenCheckInterval = setInterval(async () => {
// console.log("INSIDE tokenCheckInterval");
// try {
// const response = await fetch(
// "https://alt.uniteframework.io/auth/realms/hasura-app/protocol/openid-connect/token/introspect",
// {
// method: "POST",
// headers: {
// "Content-Type": "application/x-www-form-urlencoded",
// },
// body: `client_id=hasura-app&token=${refreshToken}&client_secret=ixoAI89JICldF5xF9Y8cgDGJrbOu6SGw`,
// }
// );
// console.log("REFRESH check");
// console.log(response.ok);
const tokenCheckInterval = setInterval(async () => {
console.log("INSIDE tokenCheckInterval");
try {
const response = await fetch(
"https://alt.uniteframework.io/auth/realms/hasura-app/protocol/openid-connect/token/introspect",
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: `client_id=hasura-app&token=${refreshToken}&client_secret=ixoAI89JICldF5xF9Y8cgDGJrbOu6SGw`,
}
);
console.log("REFRESH check");
console.log(response.ok);

// if (response.ok == false) {
// const result = await getNewAccessToken();
// const newAccessToken = result.access_token;
// const newrefreshToken = result.refresh_token;
// localStorage.setItem("token", newAccessToken);
// localStorage.setItem("token", newrefreshToken);
// } else {
// return;
// }
// } catch (error) {
// console.error("Error checking token:", error);
// }
// }, interval);
// }
// }
if (response.ok == false) {
const result = await getNewAccessToken();
const newAccessToken = result.access_token;
const newrefreshToken = result.refresh_token;
localStorage.setItem("token", newAccessToken);
localStorage.setItem("refreshToken", newrefreshToken);
} else {
return;
}
} catch (error) {
console.error("Error checking token:", error);
}
}, interval);
}
}

const skipLogin = !(
process.env.REACT_APP_OAUTH_PROXY_ENABLED == undefined ||
Expand Down

0 comments on commit b325772

Please sign in to comment.