0
0
Fork 0

Restructure login endpoint changes to include account's admin status

This commit is contained in:
Oliver Akins 2022-07-31 17:47:54 -06:00
parent a7d7c019e5
commit d962bfc01e
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99
3 changed files with 8 additions and 7 deletions

View file

@ -82,7 +82,7 @@
</button> </button>
</div> </div>
</div> </div>
<i>Group ID: {{group.id}}</i> <i v-if="admin">Group ID: {{group.id}}</i>
<hr> <hr>
<div class="lurk-messages group-messages"> <div class="lurk-messages group-messages">
<h4>Lurk Messages</h4> <h4>Lurk Messages</h4>

View file

@ -1,7 +1,6 @@
const app = new Vue({ const app = new Vue({
el: `#app`, el: `#app`,
data() {return { data() {return {
url: `https://vps.oliver.akins.me/lurk-api`,
authenticated: false, authenticated: false,
channels: [], channels: [],
channel: ``, channel: ``,
@ -12,21 +11,22 @@ const app = new Vue({
api: null, api: null,
messages: [], messages: [],
new_group: false, new_group: false,
admin: false,
}}, }},
methods: { methods: {
async tryLogin() { async tryLogin() {
try { try {
let r = await axios.post( let r = await axios.post(
`${this.url}/login`, `/login`,
undefined, undefined,
{ auth: this.login } { auth: this.login }
); );
this.api = axios.create({ this.api = axios.create({
baseURL: this.url,
validateStatus: null, validateStatus: null,
auth: this.login, auth: this.login,
}); });
this.channels.push(...r.data.sort()); this.admin = r.data.admin;
this.channels.push(...r.data.channels.sort());
this.authenticated = true; this.authenticated = true;
} catch (_) {}; } catch (_) {};
}, },

View file

@ -3,15 +3,16 @@ import { db } from "@/main";
const data: ServerRoute = { const data: ServerRoute = {
method: `POST`, path: `/login`, method: `POST`, path: `/login`,
options: {},
async handler(request, h) { 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 != "*"); let channels = access.filter(x => x != "*");
if (access.includes(`*`)) { if (access.includes(`*`)) {
channels.push(...Object.keys(db).filter(c => !channels.includes(c))); 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; export default data;