updated the route handeler
Some checks failed
NPM Installation / build (16.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (16.x, windows-latest) (push) Has been cancelled
NPM Installation / build (17.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (17.x, windows-latest) (push) Has been cancelled
NPM Installation / build (18.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (18.x, windows-latest) (push) Has been cancelled
Some checks failed
NPM Installation / build (16.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (16.x, windows-latest) (push) Has been cancelled
NPM Installation / build (17.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (17.x, windows-latest) (push) Has been cancelled
NPM Installation / build (18.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (18.x, windows-latest) (push) Has been cancelled
This commit is contained in:
parent
0677909835
commit
91337d2b3f
@ -7,9 +7,10 @@ import { jwtDecode } from 'jwt-decode'
|
|||||||
const isTokenExpired = (token) => {
|
const isTokenExpired = (token) => {
|
||||||
try {
|
try {
|
||||||
const decodedToken = jwtDecode(token)
|
const decodedToken = jwtDecode(token)
|
||||||
|
console.log('Decoded Token:', decodedToken) // Debugging
|
||||||
const currentTime = Date.now() / 1000
|
const currentTime = Date.now() / 1000
|
||||||
gging
|
console.log('Current Time:', currentTime) // Debugging
|
||||||
|
console.log('Token Expiration Time:', decodedToken.exp) // Debugging
|
||||||
return decodedToken.exp < currentTime
|
return decodedToken.exp < currentTime
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error decoding token:', error) // Debugging
|
console.error('Error decoding token:', error) // Debugging
|
||||||
@ -23,8 +24,9 @@ const ProtectedRoute = ({ element: Element }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkToken = () => {
|
const checkToken = () => {
|
||||||
const token = localStorage.getItem('authToken')
|
const token = localStorage.getItem('authToken')
|
||||||
|
console.log('Token:', token) // Debugging
|
||||||
if (!token || isTokenExpired(token)) {
|
if (!token || isTokenExpired(token)) {
|
||||||
|
console.log('Token is expired or not present, redirecting to login')
|
||||||
navigate('/login')
|
navigate('/login')
|
||||||
} else {
|
} else {
|
||||||
console.log('Token is valid')
|
console.log('Token is valid')
|
||||||
|
Loading…
Reference in New Issue
Block a user