blob: e8516747798287b1b1fae62da6ca09691c37281d (
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
27
28
29
|
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;
};
|