80 }
81
82 const response = await fetch(endpoint, {
83 method: "POST",
84 headers: {
17 const checkAuth = async () => {
18 try {
19 const response = await fetch("/api/auth/me");
20 const data = await response.json();
21
37 const handleLogout = async () => {
38 try {
39 await fetch("/api/auth/logout", { method: "POST" });
40 setUser(null);
41 } catch (err) {
41 } catch (error) {
42 console.error("SDK Error:", error);
43 throw new Error(`Failed to fetch vals: ${error.message}`);
44 }
45}
255
256 try {
257 const response = await fetch('/delete-bulk', {
258 method: 'POST',
259 headers: { 'Content-Type': 'application/json' },
283
284 try {
285 const response = await fetch('/delete-single', {
286 method: 'POST',
287 headers: { 'Content-Type': 'application/json' },
319 <div class="max-w-4xl mx-auto">
320 <h1 class="text-3xl font-bold text-red-600 mb-4">❌ Error</h1>
321 <p class="text-gray-700">Failed to fetch vals: ${error.message}</p>
322 <p class="text-sm text-gray-500 mt-2">Make sure your Val Town API token is valid.</p>
323 </div>
456});
457
458export default app.fetch;
23});
24
25export default app.fetch;
8 const [error, setError] = useState(null);
9
10 const fetchData = async () => {
11 try {
12 const userEndpoint = new URL(USER_ENDPOINT, window.location.origin);
13
14 const res = await fetch(userEndpoint);
15 const data = await res.json();
16 if (!res.ok) {
33
34 useEffect(() => {
35 fetchData();
36 }, []);
37
38 return { data, loading, error, refetch: fetchData };
39}
40
9 const [error, setError] = useState(null);
10
11 const fetchData = async () => {
12 try {
13 const projectEndpoint = new URL(PROJECT_ENDPOINT, window.location.origin);
17 if (branchId) filesEndpoint.searchParams.append("branchId", branchId);
18
19 const { project } = await fetch(projectEndpoint).then((res) =>
20 res.json()
21 );
22 const { files } = await fetch(filesEndpoint).then((res) => res.json());
23
24 setData({ project, files });
34 useEffect(() => {
35 if (!projectId) return;
36 fetchData();
37 }, [projectId, branchId]);
38
39 return { data, loading, error, refetch: fetchData };
40}
41
8 const [error, setError] = useState(null);
9
10 const fetchData = async () => {
11 try {
12 const res = await fetch(ENDPOINT);
13 const data = await res.json();
14 if (!res.ok) {
32
33 useEffect(() => {
34 fetchData();
35 }, []);
36
37 return { data, loading, error, refetch: fetchData };
38}
39
19 setError(null);
20 try {
21 const res = await fetch(ENDPOINT, {
22 method: "POST",
23 headers: {
12 setData(null);
13 setError(null);
14 const res = await fetch(ENDPOINT, {
15 method: "POST",
16 body: JSON.stringify({
7 const [loading, setLoading] = useState(true);
8
9 const fetchData = async () => {
10 const endpoint = new URL(ENDPOINT, window.location.origin);
11 endpoint.searchParams.append("projectId", projectId);
12
13 const res = await fetch(endpoint)
14 .then(res => res.json());
15 setData(res.branches);
19 useEffect(() => {
20 if (!projectId) return;
21 fetchData();
22 }, [projectId]);
23
24 return { data, loading, refetch: fetchData };
25}