diff options
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 |
