File tree Expand file tree Collapse file tree 1 file changed +23
-16
lines changed Expand file tree Collapse file tree 1 file changed +23
-16
lines changed Original file line number Diff line number Diff line change 11token = localStorage . getItem ( 'userIdTokenized' ) ;
22
33if ( 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- }
You can’t perform that action at this time.
0 commit comments