Brijesh's Git Server — argus-web @ main

Web Ul for argus

src/state/auth.js (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
import { atom, selector } from "recoil";

export const authState = atom({
  key: "authState",
  default: {
    isAuthenticated: false,
    user: null,
    token: null,
  },
});

export const isAuthenticatedSelector = selector({
  key: "isAuthenticatedSelector",
  get: ({ get }) => {
    const auth = get(authState);
    return auth?.isAuthenticated || false;
  },
});

export const userSelector = selector({
  key: "userSelector",
  get: ({ get }) => {
    const auth = get(authState);
    return auth?.user || null;
  },
});