Skip to content

Commit

Permalink
✨ Redirect the login if not login
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone committed Nov 30, 2023
1 parent 787c0e3 commit a654d31
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
27 changes: 20 additions & 7 deletions web/src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ export default function Login({ localServer }: { localServer: string }) {
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
}
}).catch(error => {
const errorcode = error.response.data as IHTTPError;
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
if (error.response != undefined) {
const errorcode = error.response.data as IHTTPError;
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
}
});
}, [])

Expand Down Expand Up @@ -181,7 +183,14 @@ export default function Login({ localServer }: { localServer: string }) {
<button
className="flex w-full items-center justify-center gap-3 rounded-md bg-[#24292F] px-3 py-1.5 text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#24292F] border-gray-800"
onClick={e => login("", "", true)}
>Anonymous</button>
>
<svg xmlns="http://www.w3.org/2000/svg"
className="h-5 w-5" viewBox="31.5 82.5 556 769">
<rect width="556" height="769" x="31.5" y="82.5" />
<path transform="translate(-79.857144,-56.433611)" fill="#ffffff"
d="M 419.05551,874.84246 c 10.2812,-3.209 18.6107,-7.75769 28.0384,-15.31151 21.1336,-16.93304 35.7755,-36.70036 90.4391,-122.09734 41.0968,-64.20239 56.5193,-92.89811 67.9874,-126.5 5.2804,-15.47191 11.3362,-42.0865 11.3366,-49.82332 1e-4,-3.10151 -0.3303,-3.76046 -1.7499,-3.49032 -2.5369,0.48275 -7.8503,8.92686 -9.7679,15.52336 -2.0554,7.0702 -9.6654,26.2121 -17.0999,43.01244 -9.5612,21.6063 -26.2848,49.91776 -51.8504,87.77784 -48.7477,72.19049 -47.3014,70.18612 -49.9192,69.18158 -1.3841,-0.53115 -1.3958,-1.04457 -0.1067,-4.69824 1.7841,-5.05673 9.7203,-18.61617 20.1828,-34.48334 4.3518,-6.6 10.7611,-17.36382 14.2428,-23.91959 3.4817,-6.55578 8.5214,-15.27602 11.1994,-19.37831 3.388,-5.18983 4.8691,-8.48436 4.8691,-10.83041 0,-1.85443 -0.4899,-3.37169 -1.0886,-3.37169 -0.5988,0 -3.4036,2.025 -6.2328,4.5 -4.6608,4.07713 -8.7622,6.06231 -7.1562,3.4638 0.3522,-0.56991 7.8676,-9.23241 16.7007,-19.25 25.2356,-28.6193 33.4111,-40.59765 38.3671,-56.2138 2.8231,-8.89524 4.4619,-24.5 2.573,-24.5 -2.3234,0 -10.0492,11.56409 -23.1529,34.6554 -7.4193,13.07435 -15.1076,25.81298 -17.085,28.30807 -20.1618,25.44015 -57.7915,43.13276 -98.9253,46.51242 -4.125,0.33892 -13.5409,1.7664 -20.9241,3.17218 -13.1742,2.50836 -13.7702,2.5341 -32,1.38248 -21.3367,-1.34788 -31.4673,-3.11017 -34.5552,-6.01113 -1.8305,-1.71963 -3.4968,-2.01942 -11.2247,-2.01942 -11.0647,0 -21.4634,-1.89195 -36.4376,-6.62955 -25.9777,-8.21896 -47.266,-19.11094 -63.2641,-32.36856 -12.2852,-10.18082 -16.6927,-16.50052 -31.0041,-44.45524 -9.6417,-18.83349 -14.9082,-27.54665 -16.65,-27.54665 -2.8273,0 3.9594,22.32503 10.5711,34.77434 10.3659,19.51776 20.6328,32.26524 46.7284,58.01811 37.2419,36.75277 44.8774,42.20863 71.4824,51.07674 22.4366,7.47873 34.659,9.12865 67.6336,9.12997 20.8422,8.4e-4 20.8575,0.002 23.8567,2.52612 2.4201,2.03635 3.6581,2.40204 6.3944,1.88871 2.1955,-0.41188 3.3932,-0.2463 3.3932,0.46911 0,0.60813 -2.7661,4.82071 -6.1469,9.3613 -8.5155,11.4367 -10.307,15.67034 -10.2637,24.2556 0.029,5.73642 0.7461,8.80511 3.973,17 3.9263,9.97113 3.9373,10.03898 3.8337,23.5 -0.097,12.64282 -0.3945,14.61116 -4.6788,31 -6.5274,24.96939 -7.3154,35 -2.7498,35 1.0611,0 5.665,-1.16602 10.2309,-2.59115 z m -54.9142,-6.40885 c -0.1187,-3.575 -2.0622,-13.925 -4.3189,-23 -6.6985,-26.93611 -8.1038,-38.34882 -5.8996,-47.91121 0.5593,-2.42617 3.2483,-9.2131 5.9756,-15.08207 4.4705,-9.6202 4.9546,-11.35198 4.9171,-17.58878 -0.048,-7.95437 -2.0902,-14.39763 -6.5567,-20.68482 -3.6905,-5.19476 -7.0379,-6.91603 -19.999,-10.28361 -5.3732,-1.39607 -14.9744,-4.73803 -21.3361,-7.42657 -6.3616,-2.68855 -14.8518,-5.91445 -18.867,-7.16868 -8.7829,-2.74348 -10.9717,-2.04072 -10.2347,3.28599 0.4952,3.57849 0.4735,12.33109 -0.063,25.35975 -0.2812,6.83172 0.14,9.45455 2.8843,17.96024 3.2407,10.04424 3.8946,14.91707 2.3324,17.38193 -2.3188,3.65854 -8.0662,-4.35362 -14.592,-20.34217 -4.9398,-12.1025 -20.1029,-41.42379 -31.5541,-61.01688 -9.0516,-15.4874 -25.3321,-41.43133 -47.3677,-75.48312 -12.41166,-19.1799 -19.7901,-33.16346 -26.21662,-49.68554 -7.86073,-20.2093 -15.90421,-33.31446 -20.44722,-33.31446 -3.6032,0 -3.24903,4.18127 1.61762,19.09752 16.28268,49.90635 40.63992,98.11942 90.38162,178.90248 19.7033,31.99905 26.2263,41.64641 34.2401,50.64047 3.3616,3.77274 13.1102,17.43453 21.6635,30.35953 12.6987,19.18908 17.3038,25.26212 25.1038,33.10579 5.2537,5.28318 11.6927,10.8402 14.3089,12.34894 6.5961,3.80395 17.6471,7.60029 21.2433,7.2977 l 3,-0.25243 -0.2158,-6.5 z m 27.1335,-58.72632 c -0.089,-4.50338 -2.0953,-7.99601 -3.682,-6.40939 -0.5438,0.54383 -0.6468,3.14679 -0.2411,6.09621 0.556,4.04281 1.0617,5.07534 2.3567,4.81245 1.2312,-0.24994 1.6279,-1.38937 1.5664,-4.49927 z m 23.5757,-120.52368 c 0,-0.6875 -0.894,-2.6 -1.9786,-4.25 -2.6837,-4.08243 -20.7025,-23.45356 -24.9324,-26.80361 -3.2733,-2.59236 -3.5268,-2.63784 -6,-1.07654 -2.9912,1.88826 -2.5678,1.41474 -15.4765,17.30928 -6.7629,8.32726 -9.5694,12.50737 -8.8681,13.20864 1.0237,1.02374 24.7043,2.41777 46.0122,2.70865 8.4183,0.11492 11.2484,-0.16106 11.2434,-1.09642 z m 57.5455,-38.18474 c 28.5871,-6.92592 43.8075,-16.34146 60.0581,-37.15269 7.6105,-9.74633 15.403,-22.16368 15.403,-24.54463 0,-1.88067 -1.0118,-2.06358 -21.4947,-3.88558 -20.6227,-1.83443 -30.0053,-4.96585 -30.0053,-10.01418 0,-2.41879 0.1401,-2.46196 7,-2.15724 3.85,0.17102 12.4734,0.95852 19.1632,1.75 16.1262,1.90794 22.2504,1.8198 40.2291,-0.57896 16.2054,-2.16214 22.4327,-4.09438 30.5019,-9.46426 7.6345,-5.08063 24.6061,-20.52887 29.2698,-26.64256 5.1892,-6.80274 6.5711,-9.59582 9.3383,-18.87516 2.0048,-6.72269 2.2877,-10.3153 2.7304,-34.66389 l 0.4939,-27.16389 -5.8633,-0.6514 c -3.2248,-0.35827 -11.2072,-1.52202 -17.7386,-2.58611 -14.4327,-2.35135 -17.6908,-2.38668 -24.1247,-0.26157 -4.2189,1.39349 -12.4986,1.77054 -53,2.41356 -26.4,0.41914 -51.825,1.07327 -56.5,1.45362 -11.794,0.95954 -15.8696,-0.32055 -23.1597,-7.2741 -3.2122,-3.06386 -5.8403,-6.10001 -5.8403,-6.747 0,-2.61342 6.1985,-10.20719 10.7036,-13.11283 12.0148,-7.74934 29.4167,-17.64593 34.363,-19.54254 13.43,-5.14965 37.0067,-6.3908 53.9334,-2.83922 17.0438,3.57613 32.8738,12.66492 40.4997,23.25289 4.9137,6.8223 5.8079,7.39397 14.388,9.19886 3.7742,0.79392 8.381,2.32255 10.2373,3.39695 4.0209,2.32725 16.1015,6.12667 19.4804,6.12667 2.3747,0 2.3946,-0.0877 2.3946,-10.53868 0,-11.98633 -1.5125,-51.0181 -3.0404,-78.46132 -3.1077,-55.81685 -11.5671,-98.55783 -24.5954,-124.26798 -13.5518,-26.74328 -43.3262,-42.58301 -101.8642,-54.19091 -43.9406,-8.7133 -87.5987,-12.339 -127.5,-10.58856 -95.5719,4.19266 -157.52,18.61114 -186.8548,43.49064 -15.61968,13.2474 -24.90804,32.96649 -32.5281,69.05681 -9.9497,47.12409 -13.46707,84.86293 -14.30664,153.5 l -0.58101,47.5 3.23662,9.5 c 7.95205,23.34048 22.05186,47.35088 34.65556,59.01456 6.94217,6.4244 17.98477,12.77291 24.30057,13.97068 7.7698,1.47351 31.4127,1.20674 47.5778,-0.53684 7.7,-0.83052 18.6125,-1.7858 24.25,-2.12284 9.9703,-0.59606 10.25,-0.55491 10.25,1.50777 0,3.06243 -3.2597,4.69687 -14,7.01969 -21.8041,4.71561 -26.4955,5.35179 -38.7132,5.24965 -14.6582,-0.12254 -15.01,0.17384 -10.2496,8.63517 8.2005,14.57599 18.7824,26.66966 30.0031,34.28948 12.8421,8.72094 43.3835,21.76894 56.1639,23.99454 8.4399,1.46975 15.1923,-0.29877 21.9778,-5.75621 6.833,-5.49562 9.223,-8.95262 9.1051,-13.16978 -0.083,-2.97953 -0.9658,-4.39183 -5.1482,-8.23972 -2.7761,-2.55411 -5.3134,-5.70411 -5.6383,-7 -0.325,-1.29588 0.1026,-6.63115 0.9503,-11.85615 2.6289,-16.20573 1.4678,-27.43417 -2.7711,-26.79696 -1.0865,0.16333 -2.4715,1.19696 -3.0776,2.29696 -0.6062,1.1 -2.5493,4.06437 -4.3181,6.5875 -5.0339,7.18101 -7.2841,13.35197 -7.2841,19.97635 0,5.47544 -0.1812,5.94353 -2.5292,6.53284 -1.8421,0.46233 -3.6156,-0.11802 -6.5275,-2.13603 -8.045,-5.57516 -12.9493,-15.39005 -12.9377,-25.89216 0.012,-11.20982 4.2953,-17.65549 15.9919,-24.06711 8.4019,-4.60561 14.1637,-10.64944 16.4992,-17.30686 2.0216,-5.76243 7.095,-34.27467 9.1094,-51.19453 0.9232,-7.75383 1.5413,-22.76461 1.628,-39.53394 l 0.1398,-27.03394 -7.9369,-15.35226 c -7.1061,-13.7451 -8.6072,-15.93995 -14.3394,-20.96606 -3.5213,-3.08759 -11.6213,-10.26394 -18,-15.94745 -19.8689,-17.70357 -28.8521,-23.13289 -43.4429,-26.25647 -14.1213,-3.02307 -20.6547,-6.19538 -20.6547,-10.029 0,-3.68669 6.0759,-5.2182 18,-4.53717 23.7661,1.35736 37.9651,8.9254 71.2477,37.97499 23.9499,20.90383 29.4533,27.64798 36.4615,44.6813 1.6972,4.125 4.01,11.325 5.1397,16 4.0166,16.62255 4.3336,24.58089 3.2011,80.36346 -0.5864,28.88329 -1.2694,53.10491 -1.5179,53.82581 -1.8176,5.27305 -7.567,48.13486 -7.6176,56.78945 -0.057,9.79567 0.061,10.38603 2.6114,13.0483 6.5803,6.86838 22.8957,10.99253 35.6553,9.01282 7.8852,-1.22344 11.4681,-2.79034 17.4437,-7.62881 2.2687,-1.83695 5.3566,-3.90112 6.8621,-4.58704 3.0567,-1.39272 1.366,-2.82857 15.6873,13.32324 10.6803,12.04551 18.4432,14.00219 37.3646,9.41803 z m -11.4424,-59.31526 c -1.5024,-7.07039 -6.1821,-17.04236 -9.4294,-20.09301 -1.3304,-1.24992 -4.7502,-2.88754 -7.5994,-3.63915 -2.8493,-0.75162 -5.8301,-1.90571 -6.6241,-2.56465 -3.6043,-2.99131 0.1744,-10.76785 4.6824,-9.63641 4.1206,1.0342 14.2711,8.13413 17.5523,12.27727 7.8785,9.94783 10.5796,21.29247 6.3468,26.65595 -1.1936,1.5125 -2.516,2.75 -2.9385,2.75 -0.4226,0 -1.3181,-2.5875 -1.9901,-5.75 z M 168.85714,472.85417 c 0,-1.4187 1.19024,-5.55457 2.64497,-9.19084 2.6349,-6.5862 2.63821,-6.62876 0.86825,-11.17055 -0.97721,-2.50754 -1.98913,-5.76675 -2.24872,-7.24269 -0.50924,-2.89535 -1.3956,-2.45712 11.97037,-5.91827 2.49333,-0.64565 4.65406,-2.2017 6.5,-4.68096 4.83255,-6.49053 12.6122,-13.69689 18.299,-16.95055 14.202,-8.12556 34.5107,-11.82919 55.9661,-10.20637 12.6744,0.95865 20.2923,3.23224 33.5,9.99818 22.4751,11.51333 31.7464,18.16421 33.1732,23.79701 1.3833,5.46121 -5.4349,13.06468 -14.0367,15.65345 -6.6929,2.01426 -23.1882,3.30599 -64.4446,5.0466 -20.5194,0.86571 -40.7694,2.16595 -45,2.88941 -15.20966,2.60101 -30.67386,6.67122 -32.75632,8.62155 -2.83511,2.65524 -4.43555,2.42216 -4.43555,-0.64597 z m 257.66667,-55.08723 c -1.3226,-1.32258 -0.6419,-11.48073 0.9805,-14.63299 6.9436,-13.49101 20.1831,-28.02453 41.8528,-45.94367 25.0509,-20.71509 43.0707,-28.75667 64.4388,-28.75667 8.886,0 13.0612,1.44801 13.0612,4.52973 0,4.11732 -6.2547,7.30363 -23.5681,12.00616 -12.3073,3.34281 -15.2048,4.80192 -25.0703,12.62474 -21.2078,16.81662 -54.6246,47.64765 -63.6116,58.68928 -1.6802,2.06432 -6.5996,2.96712 -8.0833,1.48342 z m -89.5356,-43.5972 c -2.4029,-1.22987 -9.8206,-7.35327 -16.4837,-13.60756 -14.4287,-13.54343 -20.3355,-17.70014 -35.0557,-24.66954 -21.0188,-9.95152 -34.2684,-12.97696 -53.4847,-12.21287 -19.9989,0.7952 -29.5296,5.1125 -45.08685,20.42381 -5.21393,5.13152 -9.82643,9.33003 -10.25,9.33003 -2.78253,0 2.79639,-11.02836 10.38045,-20.51997 10.2876,-12.87522 27.1804,-24.0405 42.3494,-27.99082 11.2299,-2.9245 26.3904,-3.97349 38.7728,-2.68277 29.2887,3.05299 53.8167,14.04509 74.025,33.17388 12.379,11.71775 16.4366,20.86481 13.7242,30.93804 -2.5529,9.48063 -9.7902,12.47572 -18.8909,7.81777 z m 91.9832,0.63137 c -5.8349,-4.08693 -7.8784,-16.63631 -4.039,-24.80425 2.6047,-5.54125 17.9154,-20.45382 27.5487,-26.83227 32.1866,-21.31167 65.9695,-28.28349 95.7641,-19.76297 16.8713,4.82473 35.0982,17.59234 46.2018,32.36343 5.0377,6.70152 9.7153,15.25299 9.1959,16.81135 -0.1805,0.54148 -5.0118,-3.30575 -10.7361,-8.5494 -17.9897,-16.47897 -30.5119,-21.18049 -54.0497,-20.29311 -28.025,1.05655 -47.4019,10.07505 -82,38.16491 -18.563,15.07113 -22.3125,16.80595 -27.8857,12.90231 z" />
</svg>
Anonymous</button>
</div>
<GitHubButton localServer={localServer} endpoint={endpoint} />
<GitLabButton localServer={localServer} endpoint={endpoint} />
Expand All @@ -206,8 +215,10 @@ function GitHubButton({ localServer, endpoint }: { localServer: string, endpoint
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
}
}).catch(error => {
const errorcode = error.response.data as IHTTPError;
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
if (error.response != undefined) {
const errorcode = error.response.data as IHTTPError;
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
}
});
}, []);

Expand Down Expand Up @@ -244,8 +255,10 @@ function GitLabButton({ localServer, endpoint }: { localServer: string, endpoint
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
}
}).catch(error => {
const errorcode = error.response.data as IHTTPError;
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
if (error.response != undefined) {
const errorcode = error.response.data as IHTTPError;
Notification({ level: "warning", title: errorcode.title, message: errorcode.description });
}
});
}, []);

Expand Down
25 changes: 15 additions & 10 deletions web/src/utils/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@

import axios from 'axios';

axios.interceptors.request.use((config: any) => {
const token = localStorage.getItem('token');
if ((config.headers.Authorization === undefined || config.headers.Authorization === null) &&
token !== undefined && token !== null) {
config.headers.Authorization = "Bearer " + token
}
return config;
});

export const setupResponseInterceptor = (navigate: any) => {
axios.interceptors.response.use(response => {
return response;
Expand All @@ -36,5 +27,19 @@ export const setupResponseInterceptor = (navigate: any) => {
} else {
return Promise.resolve(error?.response);
}
})
});
axios.interceptors.request.use((config: any) => {
const token = localStorage.getItem('token');
if (config.headers.Authorization === undefined || config.headers.Authorization === null) {
if (token === null) {
if (!config.url.endsWith("/api/v1/users/login")) {
navigate('/login');
return Promise.reject(new Error('request has been banned by axios interceptor'));
}
} else {
config.headers.Authorization = "Bearer " + token;
}
}
return config;
});
}

0 comments on commit a654d31

Please sign in to comment.