summaryrefslogtreecommitdiff
path: root/src-migrate/libs/auth.ts
blob: 86ce26e170c9237b1468a0dd987201410d26be68 (plain)
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 { deleteCookie, getCookie, setCookie } from 'cookies-next';
import { AuthProps } from '~/types/auth';

const COOKIE_KEY = 'auth';

export const getAuth = (): AuthProps | boolean => {
  const auth = getCookie(COOKIE_KEY);

  if (typeof auth === 'string') {
    return JSON.parse(auth);
  }

  return false;
};

export const setAuth = (user: AuthProps): boolean => {
  setCookie(COOKIE_KEY, JSON.stringify(user));

  return true;
};

export const deleteAuth = (): boolean => {
  deleteCookie(COOKIE_KEY);

  return true;
};