diff --git a/backend/src/api/staff.ts b/backend/src/api/staff.ts new file mode 100644 index 00000000..eb6b0452 --- /dev/null +++ b/backend/src/api/staff.ts @@ -0,0 +1,15 @@ +import express, { Request, Response } from "express"; +import { apiTokenAuthHandlers } from "./auth"; +import { isStaff } from "../staff"; + +export function initStaff(app: express.Express) { + const staffRouter = express.Router(); + staffRouter.use(...apiTokenAuthHandlers()); + + staffRouter.get("/status", (req: Request, res: Response) => { + const userIsStaff = isStaff(req.user.userId); + res.json({ isStaff: userIsStaff }); + }); + + app.use("/staff", staffRouter); +} diff --git a/dashboard/src/store/staff.ts b/dashboard/src/store/staff.ts new file mode 100644 index 00000000..c6855598 --- /dev/null +++ b/dashboard/src/store/staff.ts @@ -0,0 +1,24 @@ +import { get, post } from "../api"; +import { Module } from "vuex"; +import { RootState, StaffState } from "./types"; + +export const StaffStore: Module = { + namespaced: true, + + state: { + isStaff: false, + }, + + actions: { + async checkStatus({ commit }) { + const status = await get("staff/status"); + commit("setStatus", status.isStaff); + }, + }, + + mutations: { + setStatus(state: StaffState, value: boolean) { + state.isStaff = value; + }, + }, +}; diff --git a/dashboard/src/store/types.ts b/dashboard/src/store/types.ts index 4deb8fba..26ad52cc 100644 --- a/dashboard/src/store/types.ts +++ b/dashboard/src/store/types.ts @@ -24,6 +24,10 @@ export interface GuildState { }; } +export interface StaffState { + isStaff: boolean; +} + export interface ThinDocsPlugin { name: string; info: { @@ -57,4 +61,5 @@ export type RootState = { auth: AuthState; guilds: GuildState; docs: DocsState; + staff: StaffState; };