From 31d6352ab8855754ef18c01763d3c1b5a68de857 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 22 Dec 2022 15:29:18 +0700 Subject: Appbar component and auth hook (useAuth) --- src/helpers/auth.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/helpers/auth.js') diff --git a/src/helpers/auth.js b/src/helpers/auth.js index 4504564c..c09c7590 100644 --- a/src/helpers/auth.js +++ b/src/helpers/auth.js @@ -1,4 +1,5 @@ import { deleteCookie, getCookie, setCookie } from 'cookies-next'; +import { useEffect, useState } from 'react'; const getAuth = () => { let auth = getCookie('auth'); @@ -18,8 +19,27 @@ const deleteAuth = () => { return true; } +const useAuth = () => { + const [auth, setAuth] = useState({ + id: '', + name: '', + email: '', + phone: '', + mobile: '', + token: '' + }); + + useEffect(() => { + const handleIsAuthenticated = () => setAuth(getAuth()); + handleIsAuthenticated(); + }, []); + + return [auth, setAuth]; +} + export { getAuth, setAuth, - deleteAuth + deleteAuth, + useAuth }; \ No newline at end of file -- cgit v1.2.3