Fixed auth security
This commit is contained in:
@ -1,30 +1,24 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { clearAuthData, isAuthenticated } from "../utils/auth-client";
|
||||
|
||||
const SignOut = () => {
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const isAuthenticated = sessionStorage.getItem("isAuthenticated") === "true";
|
||||
setIsVisible(isAuthenticated);
|
||||
setIsVisible(isAuthenticated());
|
||||
|
||||
const handleAuthChange = () => {
|
||||
setIsVisible(sessionStorage.getItem("isAuthenticated") === "true");
|
||||
setIsVisible(isAuthenticated());
|
||||
};
|
||||
|
||||
document.addEventListener("auth-success", handleAuthChange);
|
||||
return () => document.removeEventListener("auth-success", handleAuthChange);
|
||||
}, []);
|
||||
|
||||
const handleSignOut = () => {
|
||||
sessionStorage.removeItem("isAuthenticated");
|
||||
sessionStorage.removeItem("role");
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
if (!isVisible) return null;
|
||||
|
||||
return (
|
||||
<button onClick={handleSignOut} className="btn btn-secondary">
|
||||
<button onClick={clearAuthData} className="btn btn-secondary">
|
||||
Sign Out
|
||||
</button>
|
||||
);
|
||||
|
Reference in New Issue
Block a user