diff options
| author | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-22 15:29:18 +0700 |
|---|---|---|
| committer | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-22 15:29:18 +0700 |
| commit | 31d6352ab8855754ef18c01763d3c1b5a68de857 (patch) | |
| tree | e9b7e67a994574b5b1ccc7c8ef805a899f561d3d /src/helpers | |
| parent | 7ca4c68e3c509004a84d05ebd6d66019c7e92b72 (diff) | |
Appbar component and auth hook (useAuth)
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/auth.js | 22 |
1 files changed, 21 insertions, 1 deletions
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 |
