Skip to content

Commit 7e8093d

Browse files
committed
Bug fix to validateToken in Authorization, not taking to sign in page properly
1 parent dc744e2 commit 7e8093d

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

Authorization.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
token = localStorage.getItem('userIdTokenized');
22

33
if (token) {
4-
validateTokenExpiration(token).then((response) => {
4+
validateToken(token);
5+
} else {
6+
window.location.href = './SignIn.html';
7+
}
8+
9+
async function validateToken(token) {
10+
try {
11+
const response = await fetch(
12+
'https://backend-aqzm.onrender.com/account/validateToken',
13+
{
14+
method: 'POST',
15+
headers: {
16+
Authorization: `Bearer ${token}`,
17+
'Content-Type': 'application/json',
18+
},
19+
}
20+
);
21+
522
if (!response.ok) {
623
window.location.href = './SignIn.html';
7-
}
8-
});
24+
}
25+
//This will catch the error for Unauthorized
26+
} catch (error) {
27+
window.location.href = './SignIn.html';
28+
}
929
}
1030

11-
async function validateTokenExpiration(token) {
12-
const response = await fetch(
13-
`https://backend-aqzm.onrender.com/account/validateToken`,
14-
{
15-
method: 'POST',
16-
headers: {
17-
Authorization: `Bearer ${token}`,
18-
'Content-Type': 'application/json',
19-
},
20-
}
21-
);
22-
return response;
23-
}

0 commit comments

Comments
 (0)