From b01a5a7de6303c2752358f970e8d71daa1a16596 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 17 Nov 2022 17:28:31 +0700 Subject: Auth component and cookie function --- src/helpers/auth.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/helpers/auth.js (limited to 'src/helpers') diff --git a/src/helpers/auth.js b/src/helpers/auth.js new file mode 100644 index 00000000..4504564c --- /dev/null +++ b/src/helpers/auth.js @@ -0,0 +1,25 @@ +import { deleteCookie, getCookie, setCookie } from 'cookies-next'; + +const getAuth = () => { + let auth = getCookie('auth'); + if (auth) { + return JSON.parse(auth); + } + return false; +} + +const setAuth = (user) => { + setCookie('auth', JSON.stringify(user)); + return true; +} + +const deleteAuth = () => { + deleteCookie('auth'); + return true; +} + +export { + getAuth, + setAuth, + deleteAuth +}; \ No newline at end of file -- cgit v1.2.3