1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-09 16:42:48 +00:00
Files
go-discord-bot/client/app/stores/app.store.ts

48 lines
1.0 KiB
TypeScript

import jwt_decode from 'jwt-decode';
import { action, observable } from 'mobx';
import { IClaims, Permissions } from '../model';
import { axios, StorageService } from '../services';
import { Util } from '../util';
export class AppStore {
@observable
public navbarOpen: boolean = false;
@observable
public jwt?: string;
@observable
public claims?: IClaims;
constructor() {
const jwt = StorageService.getJWT();
this.setJWT(jwt as string);
this.initNavbar();
}
private initNavbar() {
if (!Util.isMobileScreen()) {
this.navbarOpen = true;
}
}
private setJWT(jwt?: string) {
if (!jwt) {
return;
}
axios.defaults.headers['Authorization'] = `Bearer ${jwt}`;
this.jwt = jwt;
const claims = jwt_decode(jwt);
if (claims) {
this.claims = claims as IClaims;
}
}
@action
public toggleNavbar = () => {
this.navbarOpen = !this.navbarOpen;
};
public hasModPermissions = () => {
return this.claims && this.claims.permissions >= Permissions.Mod;
};
}