diff --git a/public/js/nav.js b/public/js/nav.js new file mode 100644 index 0000000..f0ac386 --- /dev/null +++ b/public/js/nav.js @@ -0,0 +1,18 @@ +document.addEventListener('DOMContentLoaded', async () => { + const adminLink = document.getElementById('admin-link'); + if (adminLink === null) { + return; + } + + const response = await fetch('/api/auth/me', { + credentials: 'same-origin', + }); + if (!response.ok) { + return; + } + + const body = await response.json(); + if (body.user && body.user.isAdmin === true) { + adminLink.hidden = false; + } +}); diff --git a/views/templates/home.php b/views/templates/home.php index 63cfbfd..2a0e13c 100644 --- a/views/templates/home.php +++ b/views/templates/home.php @@ -17,6 +17,8 @@ Today's schedule + @@ -43,6 +45,7 @@ + diff --git a/views/templates/today.php b/views/templates/today.php index 46e85b4..e6c880f 100644 --- a/views/templates/today.php +++ b/views/templates/today.php @@ -12,6 +12,8 @@

Today

Home +
@@ -23,6 +25,7 @@

+ diff --git a/views/templates/userText.php b/views/templates/userText.php index 5b2626d..51e5adb 100644 --- a/views/templates/userText.php +++ b/views/templates/userText.php @@ -14,6 +14,8 @@ My texts + @@ -22,6 +24,7 @@
+ diff --git a/views/templates/userTexts.php b/views/templates/userTexts.php index a90ca94..dbb6f5b 100644 --- a/views/templates/userTexts.php +++ b/views/templates/userTexts.php @@ -14,6 +14,8 @@ Back to Home + @@ -33,6 +35,7 @@ +