From d962bfc01e669a79a9408c2022dfbaab461b9cfe Mon Sep 17 00:00:00 2001 From: Oliver Akins Date: Sun, 31 Jul 2022 17:47:54 -0600 Subject: [PATCH] Restructure login endpoint changes to include account's admin status --- docs/index.html | 2 +- docs/script.js | 8 ++++---- src/endpoints/login.ts | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/index.html b/docs/index.html index 53f064d..5bb723b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -82,7 +82,7 @@ - Group ID: {{group.id}} + Group ID: {{group.id}}

Lurk Messages

diff --git a/docs/script.js b/docs/script.js index 2f33a22..1a246e8 100644 --- a/docs/script.js +++ b/docs/script.js @@ -1,7 +1,6 @@ const app = new Vue({ el: `#app`, data() {return { - url: `https://vps.oliver.akins.me/lurk-api`, authenticated: false, channels: [], channel: ``, @@ -12,21 +11,22 @@ const app = new Vue({ api: null, messages: [], new_group: false, + admin: false, }}, methods: { async tryLogin() { try { let r = await axios.post( - `${this.url}/login`, + `/login`, undefined, { auth: this.login } ); this.api = axios.create({ - baseURL: this.url, validateStatus: null, auth: this.login, }); - this.channels.push(...r.data.sort()); + this.admin = r.data.admin; + this.channels.push(...r.data.channels.sort()); this.authenticated = true; } catch (_) {}; }, diff --git a/src/endpoints/login.ts b/src/endpoints/login.ts index 89f64d7..4de0ad7 100644 --- a/src/endpoints/login.ts +++ b/src/endpoints/login.ts @@ -3,15 +3,16 @@ import { db } from "@/main"; const data: ServerRoute = { method: `POST`, path: `/login`, + options: {}, async handler(request, h) { - const { access } = request.auth.credentials as { username: string, access: string[] }; + const { access, admin } = request.auth.credentials as { username: string, access: string[]; admin: boolean }; let channels = access.filter(x => x != "*"); if (access.includes(`*`)) { channels.push(...Object.keys(db).filter(c => !channels.includes(c))); }; - return h.response(channels).code(200); + return h.response({ admin, channels }).code(200); }, }; export default data; \ No newline at end of file