From ef0978bc140089ac408c5782552f3055bcad59a2 Mon Sep 17 00:00:00 2001 From: majakomel Date: Mon, 28 Oct 2024 17:49:03 +0100 Subject: [PATCH] Add extra check for disabled localStorage --- hooks/useUser.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/hooks/useUser.js b/hooks/useUser.js index 7e5952bb..2bc81569 100644 --- a/hooks/useUser.js +++ b/hooks/useUser.js @@ -59,9 +59,9 @@ export const UserProvider = ({ children }) => { // new one if needed useEffect(() => { const interval = setInterval(() => { - const tokenCreatedAt = JSON.parse( - localStorage.getItem('bearer'), - )?.created_at + const tokenCreatedAt = localStorage + ? JSON.parse(localStorage.getItem('bearer'))?.created_at + : null // if localStorage is disabled in the browser it returns null if (tokenCreatedAt) { const tokenExpiry = tokenCreatedAt + TWELVE_HOURS const now = Date.now() @@ -118,8 +118,4 @@ export const UserProvider = ({ children }) => { ) } -const useUser = () => { - return useContext(UserContext) -} - export default useUser