perf(web): add validate function to js

This commit is contained in:
Masahiko AMANO 2023-01-27 17:17:47 +03:00
parent 7c58f011ca
commit deb00436f5
3 changed files with 7 additions and 4 deletions

View File

@ -26,6 +26,7 @@
<script src="/js/jquery-3.6.0.min.js"></script> <script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/jquery.cookie.js"></script> <script src="/js/jquery.cookie.js"></script>
<script src="/js/token.js"></script> <script src="/js/token.js"></script>
<script src="/js/redirector.js"></script>
</head> </head>
<body> <body>
<h1>Welcome to Tanabata!</h1> <h1>Welcome to Tanabata!</h1>

View File

@ -0,0 +1 @@
$(window).on("load", validate(() => {}, () => $(location).attr("href", "/auth")));

View File

@ -1,4 +1,4 @@
$(window).on("load", function () { function validate(onsuccess, onfailure) {
let authorized = true; let authorized = true;
if ($.cookie("token") == null) { if ($.cookie("token") == null) {
authorized = false; authorized = false;
@ -17,7 +17,8 @@ $(window).on("load", function () {
} }
}); });
} }
if (!authorized) { if (authorized) {
$(location).attr("href", "/auth"); return onsuccess;
} }
}); return onfailure;
}