Fixed auth security
This commit is contained in:
@ -8,7 +8,7 @@ interface Props {
|
||||
const { title } = Astro.props;
|
||||
---
|
||||
|
||||
<div id="auth-container" class="flex flex-col gap-4">
|
||||
<div id="auth-container">
|
||||
<SignIn client:load onSuccess={() => {}} requiredRole="guest" />
|
||||
</div>
|
||||
|
||||
@ -17,16 +17,24 @@ const { title } = Astro.props;
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Check auth state on page load
|
||||
const isAuthenticated = sessionStorage.getItem("isAuthenticated") === "true";
|
||||
if (isAuthenticated) {
|
||||
document.getElementById("auth-container")?.classList.add("hidden");
|
||||
document.getElementById("content-container")?.classList.remove("hidden");
|
||||
import { isAuthenticated } from "../utils/auth-client";
|
||||
|
||||
function updateVisibility() {
|
||||
const authContainer = document.getElementById("auth-container");
|
||||
const contentContainer = document.getElementById("content-container");
|
||||
|
||||
if (isAuthenticated()) {
|
||||
authContainer?.classList.add("hidden");
|
||||
contentContainer?.classList.remove("hidden");
|
||||
} else {
|
||||
authContainer?.classList.remove("hidden");
|
||||
contentContainer?.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
// Check auth state on page load
|
||||
updateVisibility();
|
||||
|
||||
// Add event listener for custom event from SignIn component
|
||||
document.addEventListener("auth-success", () => {
|
||||
document.getElementById("auth-container")?.classList.add("hidden");
|
||||
document.getElementById("content-container")?.classList.remove("hidden");
|
||||
});
|
||||
document.addEventListener("auth-success", updateVisibility);
|
||||
</script>
|
@ -1,6 +1,5 @@
|
||||
---
|
||||
import "../styles/global.css";
|
||||
import AuthLayout from "./AuthLayout.astro";
|
||||
import Navigation from "../components/Navigation.astro";
|
||||
|
||||
interface Props {
|
||||
@ -26,9 +25,7 @@ const { title } = Astro.props;
|
||||
<body>
|
||||
<Navigation />
|
||||
<div class="flex items-center justify-center min-h-screen">
|
||||
<AuthLayout title={title}>
|
||||
<slot />
|
||||
</AuthLayout>
|
||||
<slot />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user