import { deleteCookie, getCookie, setCookie } from 'cookies-next'; import { AuthProps } from '~/types/auth'; // @ts-ignore import camelcaseObjectDeep from 'camelcase-object-deep'; 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(camelcaseObjectDeep(user))); return true; }; export const deleteAuth = (): boolean => { deleteCookie(COOKIE_KEY); return true; };