fix: adapt to jwtDecode v4

This commit is contained in:
amhsirak
2024-11-07 21:57:56 +05:30
parent c43d13f27a
commit ba59847860

View File

@@ -1,7 +1,7 @@
import { useReducer, createContext, useEffect } from 'react';
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
import jwt_decode from 'jwt-decode';
import { jwtDecode } from "jwt-decode";
import { apiUrl } from "../apiConfig";
interface AuthProviderProps {
@@ -60,7 +60,7 @@ const AuthProvider = ({ children }: AuthProviderProps) => {
// Function to check token expiration
const checkTokenExpiration = (token: string) => {
const decodedToken: any = jwt_decode(token);
const decodedToken: any = jwtDecode(token);
const currentTime = Date.now();
const tokenExpiryTime = decodedToken.exp * 1000; // Convert to milliseconds
const timeUntilExpiry = tokenExpiryTime - currentTime;