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