Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
import { redirect } from 'next/navigation';
import { createClient } from '@/lib/supabase/server';
import { AuthProvider } from '@/components/providers/auth-provider';
import { OnboardingSignOutButton } from '@/components/auth/onboarding-sign-out-button';
import { isCloud } from '@/config/plans';
import { evaluateSubscriptionAccess } from '@/lib/billing/subscription-access';
import type { TeamRole } from '@/components/providers/role-provider';
export default async function OnboardingLayout({ children }: { children: React.ReactNode }) {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) {
redirect('/sign-in');
}
// An already-onboarded member whose org subscription has lapsed must not
// re-enter the wizard (they could re-create the brand / competitors on the
// org's existing setup): the dashboard opens read-only for them, and admins
// choose a plan in Billing. Only an admin of a new account that never had a
// subscription keeps the plan step; not-yet-onboarded users (new org
// creators) pass through.
if (isCloud()) {
const { data: profile } = await supabase
.from('profiles')
.select('organization_id, onboarding_completed, role')
.eq('id', user.id)
.single();
if (profile?.onboarding_completed && profile.organization_id) {
const { data: org } = await supabase
.from('organizations')
.select('subscription_status, stripe_subscription_id')
.eq('id', profile.organization_id)
.single();
const access = await evaluateSubscriptionAccess(
supabase,
profile.organization_id,
(profile.role ?? 'analyst') as TeamRole,
(org?.subscription_status as string | null) ?? null,
Boolean(org?.stripe_subscription_id),
);
if (access.state === 'read_only') {
redirect('/dashboard');
}
}
}
return (
<>
<AuthProvider user={user} />
<OnboardingSignOutButton />
{children}
</>
);
}