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>
</div>
</div>
<i>Group ID: {{group.id}}</i>
<i v-if="admin">Group ID: {{group.id}}</i>
<hr>
<div class="lurk-messages group-messages">
<h4>Lurk Messages</h4>

View file

@ -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 (_) {};
},

View file

@ -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;