kabisa/kudos-frontend

View on GitHub
src/support/auth.ts

Summary

Maintainability
A
0 mins
Test Coverage
C
70%
import client from "../client";
import settings from "../config/settings";
import { PATH_LOGIN } from "../routes";
import history from "./history";
import { Storage } from "./storage";

export class Auth {
  public static isLoggedIn = (): boolean =>
    Storage.getItem(settings.LOCALSTORAGE_TOKEN) !== null;

  public static hasTeam = (): boolean =>
    Storage.getItem(settings.TEAM_ID_TOKEN) !== null;

  public static isTeamAdmin = (): boolean =>
    Storage.getItem(settings.ROLE_TOKEN) === "admin";

  public static logout = async () => {
    await client.clearStore();
    Storage.clearAll();

    history.push(PATH_LOGIN);
  };
}