Skip to content

Commit

Permalink
Merge pull request #21 from Aar-if/newaltv1
Browse files Browse the repository at this point in the history
Token issue fix
  • Loading branch information
snehal0904 authored Oct 5, 2023
2 parents b325772 + 47eac41 commit 22e3ae2
Show file tree
Hide file tree
Showing 4 changed files with 748 additions and 1,721 deletions.
2 changes: 1 addition & 1 deletion packages/common-lib/src/services/courseRegistryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const courseTrackingSearch = async (

try {
const result = await post(
`${baseUrl}/altlessontracking/search/${userId}`,
`${baseUrl}/alt-course-tracking/search/${userId}`,
{ filters: params, limit },
{
headers
Expand Down
11 changes: 7 additions & 4 deletions packages/student-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ function App() {
checkTokenValidity();
}, []);

function checkTokenValidity() {
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 = 29 * 60 * 1000; // 30 minutes
// const interval = 2 * 1000; // 2 seconds

const tokenCheckInterval = setInterval(async () => {
Expand All @@ -86,10 +85,14 @@ function App() {
console.log("REFRESH check");
console.log(response.ok);

if (response.ok == false) {
if (response.ok == true) {
const result = await getNewAccessToken();

const newAccessToken = result.access_token;
const newrefreshToken = result.refresh_token;

// console.log(newAccessToken);
// console.log(newrefreshToken);
localStorage.setItem("token", newAccessToken);
localStorage.setItem("refreshToken", newrefreshToken);
} else {
Expand Down
31 changes: 19 additions & 12 deletions packages/student-app/src/api's/getNewAccessToken.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ import axios from "axios";

const getNewAccessToken = async () => {
const token = localStorage.getItem("refreshToken");
let result;
await axios.post(
"https://alt.uniteframework.io/auth/realms/hasura-app/protocol/openid-connect/token",
new URLSearchParams({
client_id: "hasura-app",
refresh_token: token,
grant_type: "refresh_token",
client_secret: "ixoAI89JICldF5xF9Y8cgDGJrbOu6SGw",
}).then((response) => {
return response;
})
);

console.log("INSIDE TOKEN API");
try {
const response = await axios.post(
"https://alt.uniteframework.io/auth/realms/hasura-app/protocol/openid-connect/token",
new URLSearchParams({
client_id: "hasura-app",
refresh_token: token,
grant_type: "refresh_token",
client_secret: "ixoAI89JICldF5xF9Y8cgDGJrbOu6SGw",
})
);

console.log(response.data);
return response.data;
} catch (error) {
console.error(error);
throw error;
}
};

export default getNewAccessToken;
Loading

0 comments on commit 22e3ae2

Please sign in to comment.