summaryrefslogtreecommitdiff
path: root/src-migrate/common/libs/auth.ts
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-11-21 06:10:12 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-11-21 06:10:12 +0000
commit0fc062268c71d53f8777c358b31e2a540d60d404 (patch)
tree0183a00dcfb14583c7dfa80da082c21630afe375 /src-migrate/common/libs/auth.ts
parent6ebe202147269100cd63ef125e877e8f693a27a1 (diff)
parent6a6ce21e5a552b0dc6cd541710a87fd0a0fd9d20 (diff)
Merged in refactor/all (pull request #116)
Refactor/all
Diffstat (limited to 'src-migrate/common/libs/auth.ts')
-rw-r--r--src-migrate/common/libs/auth.ts26
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;
+};