From b89711bbf7e30a18571f3d4f9909ab4d4be881f3 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Thu, 26 Jan 2023 21:44:03 -0700 Subject: [PATCH] get tables on admin login --- .gitignore | 1 + go.mod | 2 +- go.sum | 2 -- static/admin.js | 26 ++++++++++++++++++++++---- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c8777d7..c8c5100 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ felt +go.work user.db mongodb/data/* mongodb/.env \ No newline at end of file diff --git a/go.mod b/go.mod index bd62e44..1cbe4e4 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( go.mongodb.org/mongo-driver v1.11.0 golang.org/x/time v0.1.0 nhooyr.io/websocket v1.8.7 - nilfm.cc/git/quartzgun v0.2.0 + nilfm.cc/git/quartzgun v0.2.2 ) require ( diff --git a/go.sum b/go.sum index 124720b..efdb6e2 100644 --- a/go.sum +++ b/go.sum @@ -105,5 +105,3 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -nilfm.cc/git/quartzgun v0.2.0 h1:JJjkCbRLaMmfGLe5GQHWhBkkY6Is0roTMyWC76VtBPI= -nilfm.cc/git/quartzgun v0.2.0/go.mod h1:/DDvt1DtzNuUf3HHaP29WMei/kkdaRW+ySmEzybvVto= diff --git a/static/admin.js b/static/admin.js index a2ad7f8..4ecd62c 100644 --- a/static/admin.js +++ b/static/admin.js @@ -1,5 +1,22 @@ let adminToken = null; +async function getTables() { + try { + const headers = new Headers(); + self.set('Authorization', 'Bearer ' + adminToken.access_token); + const res = await fetch('/admin/api/table/', { + method: 'GET', + headers: headers + }); + if (res.ok) { + } else { + console.log(res); + console.log(await res.headers.get("Quartzgun-Error")); + } + } catch { + } +} + async function doLogin() { const adminUsrInput = document.getElementById("input_admin_usr"); const adminPassInput = document.getElementById("input_admin_pass"); @@ -7,12 +24,13 @@ async function doLogin() { if (adminUsrInput && adminPassInput) { adminToken = await getAdminToken(adminUsrInput.value, adminPassInput.value); + console.log(adminToken); if (adminToken) { - // render admin interface + getTables(); } else { - if (errDiv) { - errDiv.innerHTML = "Incorrect credentials"; - } + if (errDiv) { + errDiv.innerHTML = "Incorrect credentials"; + } } } }