I'm making Authentication system using jwt with httpOnly cookies in node.js and React.js.
Question is- How should i handle if someone explicitly delete cookie(contain accesstoken) by going to inspect> application >cookies tab in browser?
In my case it should navigate to Login page but it just stay in the home page unless refreshed.
Home.js(send request to verify token on component mount but if cookie deleted stayed on the same page insted going to login page)
import axios from 'axios'
import React, { useEffect } from 'react'
import './Home.css'
import { useNavigate } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux'
import Login from '../../Pages/Login';
function Home() {
const navigate = useNavigate()
useEffect(() => {
axios.get('http://localhost:9000/auth/redirecthome', { withCredentials: true })
.then((res) => {
console.log(res, 'response')
})
.catch((err) => {
console.log(err)
navigate('/login')
})
}, [])
return (
<div className='Home'>Home</div>
)
}
export default Home