Skip to content

Commit

Permalink
Add extra check for disabled localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
majakomel committed Oct 28, 2024
1 parent 7016d34 commit ef0978b
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions hooks/useUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -118,8 +118,4 @@ export const UserProvider = ({ children }) => {
)
}

const useUser = () => {
return useContext(UserContext)
}

export default useUser

0 comments on commit ef0978b

Please sign in to comment.