From 6392fea39c39962b9157106f8df979f6975e7e15 Mon Sep 17 00:00:00 2001 From: Arek Date: Tue, 14 Jun 2022 13:11:09 +0200 Subject: [PATCH] fix: :bug: Now user and unlogged user cant see ,,tworzenie turnieju" --- frontend/app.js | 37 ++++++++++++++++++++++++++++++++----- frontend/index.html | 2 +- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/frontend/app.js b/frontend/app.js index f9d9699..2ae59b2 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -64,12 +64,39 @@ function loginVisibility() { } } -function createVisibility() { + +function checkRole() { if (localStorage.getItem("token") !== null) { - document.getElementById("creator").style.display = "none"; + + fetch('https://dragonmaster.pl/inz/user', { + headers: { + Authorization: ("Bearer " + localStorage.getItem("token")) + } + }) + .then(res => res.json()) + .then(json => { + if (json['role'] == '1') { + document.getElementById("creator").style.display = "none"; + } + else { + document.getElementById("creator").style.display = ''; + } + }) } else { - document.getElementById("creator").style.display = ""; - + document.getElementById("creator").style.display = "none"; } -} \ No newline at end of file + +} + +// function creatorVisibility() { +// if (localStorage.getItem("token") == null) { +// document.getElementById("creator").style.display = "none"; +// } +// else if (checkRole()) { +// document.getElementById("creator").style.display = "none"; +// } +// else { +// document.getElementById("creator").style.display = ""; +// } +// } \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index 3cb42dd..e9e5376 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -10,7 +10,7 @@ - +