diff --git a/components/Header/Header.jsx b/components/Header/Header.jsx index 9258e3b..1f67761 100755 --- a/components/Header/Header.jsx +++ b/components/Header/Header.jsx @@ -8,42 +8,38 @@ export default function Header() { const { keycloak } = useKeycloak() const navigate = useNavigate(); - const [authenticated, setAuthenticated] = useState(false); + const refreshToken = async () => { + try { + await keycloak.updateToken(30); + } catch (error) { + console.error('Failed to refresh token:', error); + } + } - - + useEffect(() => { refreshToken() }, []) if (keycloak.authenticated) { + localStorage.setItem("refreshToken", keycloak.refreshToken) + localStorage.setItem("token", keycloak.token) const userName = keycloak.tokenParsed.preferred_username; localStorage.setItem("username", userName) } - const [username, setUsername] = useState(() => localStorage.getItem("username")) - - useEffect(() => { - if (keycloak.authenticated) { - const userName = keycloak.tokenParsed.preferred_username; - setUsername(userName) - localStorage.setItem("token", keycloak.token) - console.log("header", keycloak.token); - - } - }, [keycloak.authenticated]) - const logoutHandle = () => { - localStorage.removeItem("token") + localStorage.removeItem("username") + setIsAuthenticated(false) } - const stored_token = localStorage.getItem("token") + return (

navigate("/")}>Raman spectra search

-
{username}
- {stored_token ? +
{localStorage.getItem("username")}
+ {keycloak.authenticated ?