perf(web): add validate function to js
This commit is contained in:
parent
7c58f011ca
commit
deb00436f5
@ -26,6 +26,7 @@
|
||||
<script src="/js/jquery-3.6.0.min.js"></script>
|
||||
<script src="/js/jquery.cookie.js"></script>
|
||||
<script src="/js/token.js"></script>
|
||||
<script src="/js/redirector.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to Tanabata!</h1>
|
||||
|
||||
1
web/public/js/redirector.js
Normal file
1
web/public/js/redirector.js
Normal file
@ -0,0 +1 @@
|
||||
$(window).on("load", validate(() => {}, () => $(location).attr("href", "/auth")));
|
||||
@ -1,4 +1,4 @@
|
||||
$(window).on("load", function () {
|
||||
function validate(onsuccess, onfailure) {
|
||||
let authorized = true;
|
||||
if ($.cookie("token") == null) {
|
||||
authorized = false;
|
||||
@ -17,7 +17,8 @@ $(window).on("load", function () {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!authorized) {
|
||||
$(location).attr("href", "/auth");
|
||||
if (authorized) {
|
||||
return onsuccess;
|
||||
}
|
||||
});
|
||||
return onfailure;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user