Improve demo tennat and user get
This commit is contained in:
@@ -364,13 +364,14 @@ export function BakeryDashboard({ plan }: { plan?: string }) {
|
||||
</div>
|
||||
|
||||
{/* Setup Flow - Three States */}
|
||||
{loadingOnboarding ? (
|
||||
/* Loading state for onboarding checks */
|
||||
{/* DEMO MODE BYPASS: Demo tenants have pre-configured data, skip onboarding blocker */}
|
||||
{loadingOnboarding && !isDemoMode ? (
|
||||
/* Loading state for onboarding checks (non-demo only) */
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2" style={{ borderColor: 'var(--color-primary)' }}></div>
|
||||
</div>
|
||||
) : progressPercentage < 50 ? (
|
||||
/* STATE 1: Critical Missing (<50%) - Full-page blocker */
|
||||
) : progressPercentage < 50 && !isDemoMode ? (
|
||||
/* STATE 1: Critical Missing (<50%) - Full-page blocker (non-demo only) */
|
||||
<SetupWizardBlocker
|
||||
criticalSections={setupSections}
|
||||
/>
|
||||
|
||||
@@ -198,26 +198,29 @@ const DemoPage = () => {
|
||||
localStorage.setItem('virtual_tenant_id', sessionData.virtual_tenant_id);
|
||||
localStorage.setItem('demo_expires_at', sessionData.expires_at);
|
||||
|
||||
// BUG FIX: Store the session token as access_token for authentication
|
||||
if (sessionData.session_token) {
|
||||
// Store the session token as access_token for authentication
|
||||
if (sessionData.session_token && sessionData.user) {
|
||||
console.log('🔐 [DemoPage] Storing session token:', sessionData.session_token.substring(0, 20) + '...');
|
||||
localStorage.setItem('access_token', sessionData.session_token);
|
||||
|
||||
// CRITICAL FIX: Update Zustand auth store with demo auth
|
||||
// This ensures the token persists across navigation and page reloads
|
||||
// Use complete user data from backend (like a real login response)
|
||||
setDemoAuth(sessionData.session_token, {
|
||||
id: 'demo-user',
|
||||
email: 'demo@bakery.com',
|
||||
full_name: 'Demo User',
|
||||
is_active: true,
|
||||
is_verified: true,
|
||||
created_at: new Date().toISOString(),
|
||||
tenant_id: sessionData.virtual_tenant_id,
|
||||
}, tier); // NEW: Pass subscription tier to setDemoAuth
|
||||
id: sessionData.user.id,
|
||||
email: sessionData.user.email,
|
||||
full_name: sessionData.user.full_name,
|
||||
is_active: sessionData.user.is_active,
|
||||
is_verified: sessionData.user.is_verified,
|
||||
created_at: sessionData.user.created_at,
|
||||
tenant_id: sessionData.user.tenant_id,
|
||||
role: sessionData.user.role as any,
|
||||
}, tier);
|
||||
|
||||
console.log('✅ [DemoPage] Demo auth set in store');
|
||||
// Store tenant data in localStorage for tenant initializer
|
||||
localStorage.setItem('demo_tenant_data', JSON.stringify(sessionData.tenant));
|
||||
|
||||
console.log('✅ [DemoPage] Demo auth set in store with complete user data');
|
||||
} else {
|
||||
console.error('❌ [DemoPage] No session_token in response!', sessionData);
|
||||
console.error('❌ [DemoPage] Missing session_token or user in response!', sessionData);
|
||||
}
|
||||
|
||||
// Now poll for status until ready
|
||||
|
||||
Reference in New Issue
Block a user