Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token issue fix #21

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aar-if Please remove consoles

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

export default getNewAccessToken;
Loading