diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-30 09:21:30 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-30 09:21:30 +0700 |
| commit | e8c414325a1e32474e740cc6e7dca8396affc5e3 (patch) | |
| tree | e84feb31cd8619d208b4558c5fcf30becc5337e0 /src-migrate/common/libs/auth.ts | |
| parent | 1694c12f75ad06c5e40d6f9a66e245c3e683146c (diff) | |
| parent | c82110f7d3a2f85de99045fde7b579e369f15b2c (diff) | |
Merge branch 'refactor/all' into development
Diffstat (limited to 'src-migrate/common/libs/auth.ts')
| -rw-r--r-- | src-migrate/common/libs/auth.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src-migrate/common/libs/auth.ts b/src-migrate/common/libs/auth.ts new file mode 100644 index 00000000..fb4e836a --- /dev/null +++ b/src-migrate/common/libs/auth.ts @@ -0,0 +1,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; +}; |
