Fixed auth security
This commit is contained in:
@ -1,10 +1,28 @@
|
|||||||
<button id="signout-btn" class="btn btn-secondary">Sign Out</button>
|
{/* Initially hidden */}
|
||||||
|
<button id="signout-btn" class="btn btn-secondary hidden">Sign Out</button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { clearAuthData } from "../utils/auth-client";
|
import { clearAuthData, isAuthenticated } from "../utils/auth-client";
|
||||||
|
|
||||||
|
function updateVisibility() {
|
||||||
|
const button = document.getElementById("signout-btn");
|
||||||
|
if (button) {
|
||||||
|
if (isAuthenticated()) {
|
||||||
|
button.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
button.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add click handler to the button
|
// Add click handler to the button
|
||||||
document.getElementById("signout-btn")?.addEventListener("click", () => {
|
document.getElementById("signout-btn")?.addEventListener("click", () => {
|
||||||
clearAuthData();
|
clearAuthData();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check visibility on load
|
||||||
|
updateVisibility();
|
||||||
|
|
||||||
|
// Update visibility when auth state changes
|
||||||
|
document.addEventListener("auth-success", updateVisibility);
|
||||||
</script>
|
</script>
|
Reference in New Issue
Block a user