Browse Source

chore(web): check for token expiration on launch and redirect to login

pull/8/head
isra el 2 years ago
parent
commit
aa8201eaef
  1. 18
      web/components/Navbar.tsx

18
web/components/Navbar.tsx

@ -19,12 +19,30 @@ import Router from 'next/router'
import { useDispatch, useSelector } from 'react-redux'
import { logout, selectAuthUser } from '../store/authSlice'
import Image from 'next/image'
import { useEffect } from 'react'
import { authService } from '../services/authService'
export default function Navbar() {
const dispatch = useDispatch()
const { colorMode, toggleColorMode } = useColorMode()
const authUser = useSelector(selectAuthUser)
useEffect(() => {
const timout = setTimeout(async () => {
if (authUser) {
authService
.whoAmI()
.catch((e) => {
if (e.response.status === 401) {
dispatch(logout())
}
})
.then((res) => {})
}
}, 5000)
return () => clearTimeout(timout)
}, [authUser, dispatch])
return (
<>
<Box

Loading…
Cancel
Save