Fixed auth
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import type { RegistryItem } from "../lib/types";
|
||||
import { fetchWithAuth } from "../utils/auth-client";
|
||||
import { fetchWithAuth, getAuthToken } from "../utils/auth-client";
|
||||
|
||||
const RegistryList = () => {
|
||||
const [registryItems, setRegistryItems] = useState<RegistryItem[]>([]);
|
||||
@ -9,11 +9,14 @@ const RegistryList = () => {
|
||||
const [claimantName, setClaimantName] = useState("");
|
||||
const [claimedItems, setClaimedItems] = useState<Set<string>>(new Set());
|
||||
|
||||
useEffect(() => {
|
||||
fetchRegistryItems();
|
||||
}, []);
|
||||
|
||||
const fetchRegistryItems = async () => {
|
||||
// Don't try to fetch if we don't have a token yet
|
||||
if (!getAuthToken()) {
|
||||
setError("No authentication token found");
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
@ -26,6 +29,7 @@ const RegistryList = () => {
|
||||
if (data.length === 0) {
|
||||
document.dispatchEvent(new Event("registry-empty"));
|
||||
}
|
||||
setError(null);
|
||||
} catch (e: any) {
|
||||
setError(e.message);
|
||||
console.error("Failed to fetch registry items:", e);
|
||||
@ -34,6 +38,20 @@ const RegistryList = () => {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Only fetch if we have a token
|
||||
if (getAuthToken()) {
|
||||
fetchRegistryItems();
|
||||
}
|
||||
|
||||
// Add listener for auth success to retry fetching
|
||||
const handleAuthSuccess = () => {
|
||||
fetchRegistryItems();
|
||||
};
|
||||
document.addEventListener("auth-success", handleAuthSuccess);
|
||||
return () => document.removeEventListener("auth-success", handleAuthSuccess);
|
||||
}, []);
|
||||
|
||||
const handleItemClick = (itemId: string) => {
|
||||
const newClaimedItems = new Set(claimedItems);
|
||||
if (newClaimedItems.has(itemId)) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
---
|
||||
import Layout from "../layouts/Layout.astro";
|
||||
import SignIn from "../components/SignIn.tsx";
|
||||
import SignOut from "../components/SignOut.tsx";
|
||||
---
|
||||
|
||||
<Layout title="Welcome">
|
||||
@ -75,10 +74,6 @@ import SignOut from "../components/SignOut.tsx";
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center mt-4">
|
||||
<SignOut client:load />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
|
@ -2,7 +2,6 @@
|
||||
import AdminLayout from "../../layouts/AdminLayout.astro";
|
||||
import RegistryManager from "../../components/RegistryManager.tsx";
|
||||
import SignIn from "../../components/SignIn.tsx";
|
||||
import SignOut from "../../components/SignOut.tsx";
|
||||
---
|
||||
|
||||
<AdminLayout title="Registry Manager">
|
||||
@ -17,7 +16,6 @@ import SignOut from "../../components/SignOut.tsx";
|
||||
<RegistryManager client:load />
|
||||
<div class="flex flex-row gap-2 justify-center items-center mt-4">
|
||||
<a class="btn btn-primary" href="/">Back to Home</a>
|
||||
<SignOut client:load />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,7 +2,6 @@
|
||||
import Layout from "../../layouts/Layout.astro";
|
||||
import RegistryList from "../../components/RegistryList.tsx";
|
||||
import SignIn from "../../components/SignIn.tsx";
|
||||
import SignOut from "../../components/SignOut.tsx";
|
||||
---
|
||||
|
||||
<Layout title="Registry">
|
||||
@ -22,7 +21,6 @@ import SignOut from "../../components/SignOut.tsx";
|
||||
</div>
|
||||
<div class="flex flex-row gap-2 justify-center items-center mt-4">
|
||||
<a class="btn btn-primary" href="/">Back to Home</a>
|
||||
<SignOut client:load />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,7 +2,6 @@
|
||||
import Layout from "../layouts/Layout.astro";
|
||||
import RSVP from "../components/RSVP.tsx";
|
||||
import SignIn from "../components/SignIn.tsx";
|
||||
import SignOut from "../components/SignOut.tsx";
|
||||
---
|
||||
|
||||
<Layout title="RSVP">
|
||||
@ -19,7 +18,6 @@ import SignOut from "../components/SignOut.tsx";
|
||||
<RSVP client:load />
|
||||
<div class="flex flex-row gap-2 justify-center items-center mt-4">
|
||||
<a class="btn btn-primary" href="/">Back to Home</a>
|
||||
<SignOut client:load />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,7 +2,6 @@
|
||||
import AdminLayout from "../../layouts/AdminLayout.astro";
|
||||
import RSVPManager from "../../components/RSVPManager.tsx";
|
||||
import SignIn from "../../components/SignIn.tsx";
|
||||
import SignOut from "../../components/SignOut.tsx";
|
||||
---
|
||||
|
||||
<AdminLayout title="RSVP Manager">
|
||||
@ -17,7 +16,6 @@ import SignOut from "../../components/SignOut.tsx";
|
||||
<RSVPManager client:load />
|
||||
<div class="flex flex-row gap-2 justify-center items-center mt-4">
|
||||
<a class="btn btn-primary" href="/">Back to Home</a>
|
||||
<SignOut client:load />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,7 +2,6 @@
|
||||
import Layout from "../../layouts/Layout.astro";
|
||||
import RSVP from "../../components/RSVP.tsx";
|
||||
import SignIn from "../../components/SignIn.tsx";
|
||||
import SignOut from "../../components/SignOut.tsx";
|
||||
---
|
||||
|
||||
<Layout title="RSVP">
|
||||
@ -19,7 +18,6 @@ import SignOut from "../../components/SignOut.tsx";
|
||||
<RSVP client:load />
|
||||
<div class="flex flex-row gap-2 justify-center items-center mt-4">
|
||||
<a class="btn btn-primary" href="/">Back to Home</a>
|
||||
<SignOut client:load />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user