diff --git a/public/index.html b/public/index.html index ca170f1c94da69385f6698bfa665cb123e73c96c..97a91fcdae16c5915876c18c9f3a4e362e7e6cf3 100644 --- a/public/index.html +++ b/public/index.html @@ -6,6 +6,7 @@ <title>ToDo</title> <link rel="stylesheet" href="./css/index.css" /> <script src="./js/index.js" defer></script> + <script src="./js/authorization.js" defer></script> </head> <body> <div class="container"> diff --git a/public/js/authorization.js b/public/js/authorization.js new file mode 100644 index 0000000000000000000000000000000000000000..61df3f53043e7b854df6632cbaf1e7907316854b --- /dev/null +++ b/public/js/authorization.js @@ -0,0 +1,11 @@ +document.addEventListener('DOMContentLoaded', async () => { + // Event for checking if the user is logged in + try { + const res = await fetch('/api/users/loggedin', { method: 'POST' }); + if (!res.ok) { + window.location.href = 'login.html'; + } + } catch (err) { + console.error('Error while checking if a user is logged in:', err); + } +}); \ No newline at end of file diff --git a/public/js/index.js b/public/js/index.js index a2532025fac685cc0ace84eb709674bcada54592..5d8064574ffe7b926ddbcceae836114e138a021f 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,14 +1,4 @@ document.addEventListener('DOMContentLoaded', async () => { - // Event for checking if the user is logged in - try { - const res = await fetch('/api/users/loggedin', { method: 'POST' }); - if (!res.ok) { - window.location.href = 'login.html'; - } - } catch (err) { - console.error('Error while checking if a user is logged in:', err); - } - const logoutBtn = document.getElementById('logout-btn'); // Event for the logout button