Fix fetch orgs auth gating

Ensure profile page fetches organizations only after user is available to attach bearer token
This PR guards the /organizations call behind a user presence check to avoid 401 due to missing auth token on initial render.

X-Lovable-Edit-ID: edt-b4dabc36-942c-4632-a80d-4f981ad3d194
This commit is contained in:
gpt-engineer-app[bot]
2026-01-07 14:35:54 +00:00
+7 -2
View File
@@ -25,8 +25,13 @@ export default function ProfilePage() {
}
}, [user?.full_name]);
// Fetch organizations
// Fetch organizations only when user is available
useEffect(() => {
if (!user) {
setOrgsLoading(false);
return;
}
const fetchOrgs = async () => {
try {
const response = await api.users.organizations();
@@ -45,7 +50,7 @@ export default function ProfilePage() {
};
fetchOrgs();
}, []);
}, [user]);
const getInitials = (fullName: string | null) => {
if (!fullName) return "?";