Skip to content

Unrestricted Open-source alternative to AI video platforms — Free AI image & video generation studio with 600+ models (Flux, Midjourney, Kling, Sora, Veo). No content filters. Self-hosted, MIT licensed.

Fix Design Agent studio balance/auth for white-label end users

Anil-matchabb738f88d639
diff --git a/packages/studio/src/components/DesignAgentStudio.jsx b/packages/studio/src/components/DesignAgentStudio.jsx
index a02aaae3..f4f9403b 100644
--- a/packages/studio/src/components/DesignAgentStudio.jsx
+++ b/packages/studio/src/components/DesignAgentStudio.jsx
@@ -7,6 +7,8 @@ import { getUserBalance } from '../muapi';
export default function DesignAgentStudio({
apiKey,
+ userEmail,
+ balance,
isHeaderVisible,
onToggleHeader,
onGenerationStart,
@@ -16,11 +18,30 @@ export default function DesignAgentStudio({
}) {
const [userData, setUserData] = useState(null);
- useEffect(() => {
+ // Written synchronously during render (not inside an effect below) so it's already in
+ // localStorage before CreativeCanvas's own mount effects read it — passive effects run
+ // child-before-parent within a commit, so setting this from *our* useEffect ran after
+ // CreativeCanvas's first sessions/agent-skills fetch had already gone out unauthenticated.
+ if (typeof window !== 'undefined' && apiKey) {
sessionStorage.setItem("fromDesignAgent", "true");
- if (!apiKey) return;
localStorage.setItem("token", apiKey);
-
+ }
+
+ useEffect(() => {
+ if (!apiKey) return;
+
+ // White-label shells already know the end user's identity/credit balance (fetched via
+ // /api/whitelabel/balance) and pass them in directly — GET /account/balance explicitly
+ // 403s for white-label end users, so getUserBalance() below must stay BYOK-only.
+ if (userEmail !== undefined || balance !== undefined) {
+ setUserData({
+ username: userEmail?.split('@')[0] || 'Studio User',
+ email: userEmail,
+ balance: balance || 0,
+ });
+ return;
+ }
+
const fetchUser = async () => {
try {
const data = await getUserBalance(apiKey);
@@ -35,7 +56,7 @@ export default function DesignAgentStudio({
};
fetchUser();
- }, [apiKey]);
+ }, [apiKey, userEmail, balance]);
return (
<div className="h-full w-full bg-black overflow-hidden design-agent-studio">