diff --git a/package.json b/package.json index 689eb8dc..cdde5dfa 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@mui/material": "^5.14.11", "@tanstack/react-query": "^4.10.3", "@tanstack/react-query-devtools": "^4.11.0", - "jwt-decode": "^3.1.2", + "jwt-decode": "^4.0.0", "leaflet": "^1.9.2", "leaflet-draw": "^1.0.4", "lodash": "^4.17.21", diff --git a/src/components/useAuth.tsx b/src/components/useAuth.tsx index 3c52ca2e..b6faf74c 100644 --- a/src/components/useAuth.tsx +++ b/src/components/useAuth.tsx @@ -1,7 +1,7 @@ import React, { createContext, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react' import { login as loginApi } from '../api/Auth' import { useLocation, useNavigate } from 'react-router' -import decode from 'jwt-decode' +import { jwtDecode } from 'jwt-decode' export type Roles = 'user' | 'admin' @@ -45,7 +45,7 @@ export function AuthProvider({ children }: { children: ReactNode }): JSX.Element let user: User try { - user = decode(token) as User + user = jwtDecode(token) as User } catch (error) { setError(error as Error) setLoadingInitial(false) @@ -70,7 +70,7 @@ export function AuthProvider({ children }: { children: ReactNode }): JSX.Element localStorage.setItem('token', response.token) setToken(response.token) - const user = decode(response.token) as User + const user = jwtDecode(response.token) as User setUser(user) navigate('/') }) diff --git a/yarn.lock b/yarn.lock index 74f2e8f3..fbd252ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6724,10 +6724,10 @@ jsonfile@^6.0.1: object.assign "^4.1.4" object.values "^1.1.6" -jwt-decode@*, jwt-decode@^3.1.2: - version "3.1.2" - resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.2.tgz#3fb319f3675a2df0c2895c8f5e9fa4b67b04ed59" - integrity sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A== +jwt-decode@*, jwt-decode@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-4.0.0.tgz#2270352425fd413785b2faf11f6e755c5151bd4b" + integrity sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA== jwt-encode@^1.0.1: version "1.0.1"