// frontend/src/components/UserProfile.tsx
import { useState, useEffect } from "react";
import Client from "../client";
const client = new Client(import.meta.env.VITE_API_URL);
export function UserProfile({ userId }: { userId: string }) {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
client.user.getUser({ id: userId })
.then(setUser)
.catch(setError)
.finally(() => setLoading(false));
}, [userId]);
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
return (
<div>
<h1>{user.name}</h1>
<p>{user.email}</p>
</div>
);
}
Configure CORS in your encore.app file:
| Option | Description |
|---|---|
| allow_origins_without_credentials | Origins allowed for non-credentialed requests (default: ["*"]) |
| allow_origins_with_credentials | Origins allowed for credentialed requests (cookies, auth headers) |
| allow_headers | Additional request headers to allow |
| expose_headers | Additional response headers to expose |
| debug | Enable CORS debug logging |
For authenticated requests, pass the Authorization header:
With TanStack Query, configure a default fetcher:
If you prefer not to use the generated client: