diff --git a/gambling.js b/gambling.js index 72b4f5a..8c7f01b 100644 --- a/gambling.js +++ b/gambling.js @@ -108,12 +108,12 @@ app.get("/", authenticateToken, (request, response) => { response.sendFile(path.join(__dirname, ".\\public\\home.html")); }); -app.post("/balance", authenticateToken, (request, response) => { +app.get("/balance", authenticateToken, (request, response) => { /* #swagger.security = [{ "bearerAuth": [] }] */ const username = request.user.username; - + console.log(username); const allUsers = get_data(); const me = allUsers.find(u => u.username === username); @@ -121,7 +121,7 @@ app.post("/balance", authenticateToken, (request, response) => { return response.status(404).json({ error: "User not found" }); } - response.json({ balance: me.money }); + response.json({ balance: me.money }).status(200); }); app.post("/verify", authenticateToken, (request, response) => { diff --git a/public/frontend_home.js b/public/frontend_home.js new file mode 100644 index 0000000..6b5c1af --- /dev/null +++ b/public/frontend_home.js @@ -0,0 +1,19 @@ +document.addEventListener("DOMContentLoaded", async () => { + const logoutButton = document.getElementById("logout"); + const balance = document.getElementById("balance"); + try { + const balanceRes = await fetch('/balance', { + method: "GET", + headers: { + "Content-Type": "application/json", + } + }); + if (balanceRes.ok) { + const balanceData = await balanceRes.json(); + console.log(balanceData); + balance.innerHTML = balanceData.balance; + } + } catch (error) { + console.log(error); + } +}); \ No newline at end of file diff --git a/public/home.html b/public/home.html index 52eb118..2fa4810 100644 --- a/public/home.html +++ b/public/home.html @@ -4,13 +4,13 @@ Home + - - + + +
+ Balance: $0 +
\ No newline at end of file diff --git a/public/styles_home.css b/public/styles_home.css index 5c5f0be..ca5ffd6 100644 --- a/public/styles_home.css +++ b/public/styles_home.css @@ -46,6 +46,8 @@ button.logout { font-size: 14px; } -button.balance { +.balance { margin-top: 20px; + color: #0f0; + text-shadow: 0 0 5px #0f0, 0 0 10px #0f0; } \ No newline at end of file