/iblai-vibe:iblai-vibe-authfrom ibl.ai vibe
Adds ibl.ai SSO authentication to a vanilla Next.js app, redirecting unauthenticated users to login.iblai.app and returning a session without API token management.
Ships in ibl.ai vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Add ibl.ai SSO authentication to a vanilla Next.js app. After completion, unauthenticated users are redirected to login.iblai.app and returned with a session -- no API tokens to manage.
Templates: the auth files this skill creates (providers, store, SSO callback,
lib/iblai/*) are bundled here as ready-to-copy files —assets/. Step 3 copies them into the project; see/iblai-vibe-scaffoldfor the shared patch mechanics.
If .env.local already has NEXT_PUBLIC_MAIN_TENANT_KEY set to a real
value (not a placeholder like your-main-platform, your-tenant, your-platform,
your-tenant-key, test-tenant, main, or empty), keep that value.
Common setup (brand, conventions, env files, verification): see docs/skill-setup.md.
Sign-in is the same hosted round trip for every ibl.ai front end
(login.<domain>/login?app=…&redirect-to=<origin>&tenant=<org> → back to
/sso-login-complete?data=…); what differs is where the org comes from.
/iblai-vibe-start records the answer in iblai.env as ARCHITECTURE=;
if it is missing, ask one question before writing files:
ARCHITECTURE | The app is for | Org key | This skill does |
|---|---|---|---|
single-org (default) | members of one organization — yours, or the customer you deploy to | pinned: NEXT_PUBLIC_MAIN_TENANT_KEY (never main) | everything below as written |
multi-org | users who belong to many organizations (the os.ibl.ai model) | from the URL (/platform/[org]/…) plus a switcher; NEXT_PUBLIC_MAIN_TENANT_KEY=main is the community org | everything below, then Going multi-org at the end |
headless | nobody signs in — scripts, CI, a backend | IBLAI_ORG per call | not this skill: /iblai-api-login and the iblai-api-* family |
The parameters, tokens, anonymous access, organization switching, native shells, and the OS's implementation are in docs/auth-model.md.
Before running this skill, ask the user:
Are you starting a new project from scratch? If so, vibe-starter (https://github.com/iblai/base/tree/main/skills/start/iblai-vibe-ops-init/assets/vibe-starter) is a pre-wired Next.js 16 + Tailwind v4 + shadcn/ui template with ibl.ai SSO auth, a responsive navbar, and profile/account/notifications pages already in place. Want to use that instead?
If yes, copy the bundled starter template from the installed
iblai-vibe-ops-init skill's assets/vibe-starter/ directory (a sibling of
this skill's directory), or fetch it from the vibe repo if those assets are
not installed -- tell the user which path you took:
cp -a <skills-dir>/iblai-vibe-ops-init/assets/vibe-starter/. .
# or, without local assets:
git clone --depth 1 https://github.com/iblai/base.git vibe-tmp && cp -a vibe-tmp/skills/start/iblai-vibe-ops-init/assets/vibe-starter/. . && rm -rf vibe-tmp
pnpm install --ignore-scripts
Run with
--ignore-scriptsto skip package lifecycle (postinstall) scripts.
If they prefer to wire auth into an existing app, continue below.
Want a complete app from scratch? Use vibe-starter (Step 0 above) —
it ships with auth, a navbar, and profile/account/notifications already
wired, so you can skip this skill. For the underlying whole-app scaffold and
its templates, see /iblai-vibe-scaffold.
This skill adds auth to a vanilla Next.js app or an existing project by creating the auth files directly (Step 3).
app/ directory)Before proceeding, check for a iblai.env
in the project root. Look for PLATFORM, DOMAIN, and TOKEN variables.
If the file does not exist or is missing these variables, tell the user:
"You need an iblai.env with your platform configuration. Copy the
bundled template and fill in your values:
cp iblai.env.example iblai.env (vibe-starter ships the example) — or,
when the project has no iblai.env.example:
curl -o iblai.env https://raw.githubusercontent.com/iblai/vibe/refs/heads/main/iblai.env"
If PLATFORM is set to a real value (not your-platform or your-main-platform), use it
as the platform key in Step 3. Otherwise use the placeholder and tell the user to replace it.
STOP here. You MUST ask the user these questions before proceeding to Step 3. Do NOT skip this step.
Fetch the org's platform_name (GET https://api.{domain}/dm/api/core/orgs/{platform}/metadata/), ask the user what the app does and whether they want the navbar, generate a headline and tagline, save the AUTH_* values to iblai.env, STOP for the user to review, then upload the logo (POST …/platforms/{platform}/public-image-assets/, three categories) and PUT auth_web_skillsai + auth_web_mentorai into the org metadata. The exact questions, defaults, upload table, and JSON payload are in references/auth-interface.md — follow it verbatim. Never drop the org's other metadata keys (GET, merge, PUT — see /iblai-vibe-org-metadata).
Copy the bundled assets/ files into the project — nothing to
substitute: the org key comes from NEXT_PUBLIC_MAIN_TENANT_KEY at runtime.
For a src/ layout, place files under src/lib, src/store,
src/providers accordingly.
Template (assets/…) | Destination |
|---|---|
config.ts | lib/iblai/config.ts |
auth-utils.ts | lib/iblai/auth-utils.ts |
storage-service.ts | lib/iblai/storage-service.ts |
tenant.ts | lib/iblai/tenant.ts |
iblai-store.ts | store/iblai-store.ts |
iblai-providers.tsx | providers/iblai-providers.tsx |
iblai-styles.css | app/iblai-styles.css |
sso-login-complete-page.tsx | app/sso-login-complete/page.tsx |
Then apply the project patches (each is idempotent — check for a marker
before editing; full mechanics in
/iblai-vibe-scaffold → add-command):
next.config — add the @reduxjs/toolkit webpack resolve.alias that
deduplicates RTK. Without it the SDK binds a different ReactReduxContext
and RTK Query hooks silently return undefined.globals.css — add @import "./iblai-styles.css";..env.local — set NEXT_PUBLIC_MAIN_TENANT_KEY=<platform key> (←
PLATFORM) and, for server-side platform calls, IBLAI_API_KEY (←
TOKEN). Nothing else needs deriving — the URL vars default in the
copied lib/iblai/config.ts.The SSO callback at app/sso-login-complete/page.tsx must stay outside
the providers (Step 5 / Troubleshooting), or it deadlocks on login.
Add the SDK dependencies and install:
pnpm add @iblai/iblai-js @reduxjs/toolkit react-redux sonner lucide-react
pnpm install --ignore-scripts
Run with
--ignore-scriptsto skip package lifecycle (postinstall) scripts.
These are:
@iblai/iblai-js -- SDK (auth, data layer, UI components)@reduxjs/toolkit + react-redux -- state management (SDK uses RTK Query)sonner -- toast notificationslucide-react -- iconsIf package.json does not already have a "test" script (or it still has the
default create-next-app placeholder), add vitest:
pnpm add -D vitest
Then set the test script in package.json:
"scripts": {
"test": "vitest run"
}
Open app/layout.tsx and wrap {children} with the generated IblaiProviders.
Add viewport-fit=cover to the metadata so mobile builds (iOS/Android) respect
safe area insets and don't overlap with the status bar.
If you have no existing providers:
import type { Metadata, Viewport } from "next";
import { IblaiProviders } from "@/providers/iblai-providers";
export const metadata: Metadata = {
title: "My App",
};
export const viewport: Viewport = {
width: "device-width",
initialScale: 1,
viewportFit: "cover",
};
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<IblaiProviders>{children}</IblaiProviders>
</body>
</html>
);
}
If you have existing providers (e.g., custom contexts):
import type { Metadata, Viewport } from "next";
import { IblaiProviders } from "@/providers/iblai-providers";
import { MyProvider } from "./my-provider";
export const metadata: Metadata = {
title: "My App",
};
export const viewport: Viewport = {
width: "device-width",
initialScale: 1,
viewportFit: "cover",
};
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<IblaiProviders>
<MyProvider>
{children}
</MyProvider>
</IblaiProviders>
</body>
</html>
);
}
IblaiProviders must be the outermost provider -- it contains Redux, Auth,
and Organization providers that other components depend on. Place your own providers
inside it.
The providers also route a credits 402 from any REST call: they dispatch it
as the creditsexhausted DOM event, which nothing listens for until
CreditExhaustionHandler is mounted in the signed-in layout
(/iblai-vibe-credit-exhaustion, Step 2; vibe-starter ships it in
app/(app)/layout.tsx). Without it, running out of credits shows nothing.
Step 3 created .env.local with the platform key. Verify it has the
right value (edit the line directly if not):
NEXT_PUBLIC_MAIN_TENANT_KEY=your-main-platform
The API URLs default to hosted iblai.app in the copied
lib/iblai/config.ts; override them in .env.local only when
self-hosting.
Verify app/globals.css has the SDK imports (Step 3 adds these):
@import '@iblai/iblai-js/web-containers/styles';
@source "../node_modules/@iblai/iblai-js/dist/web-containers/source";
If these lines are missing, add them near the top of globals.css.
After adding auth, check if app/page.tsx still has the default Next.js
content (look for next/image, vercel.svg, Vercel, or
Get started by editing). If it does, replace it with the ibl.ai home page —
copy assets/home-page.tsx into
app/(app)/page.tsx (or app/page.tsx), then change the heading, tagline and links.
If the user has already customized their home page, skip this step.
If the user said yes to the navbar question in Step 2, run /iblai-vibe-navbar
now before starting the dev server.
Start the dev server so the user can see the result:
pnpm dev
axd_token, userData, tenants| File | Purpose |
|---|---|
app/sso-login-complete/page.tsx | SSO callback -- stores tokens from URL into localStorage, then lands only on a path of this origin |
lib/iblai/config.ts | Environment variable accessors (API URLs, platform key, auth URL) |
lib/iblai/storage-service.ts | localStorage wrapper implementing the SDK's StorageService interface |
lib/iblai/auth-utils.ts | redirectToAuthSpa() and handleLogout() (the SDK's, as iblai/os calls them, with this app's settings), tokenRefreshUrl(), safeRedirectPath() (the landing guard) |
store/iblai-store.ts | Redux store with coreApiSlice, mentorReducer, mentorMiddleware, and the slice keys the SDK <Chat> and the credits flows hard-code (chat, chatInput, chatSliceShared, files, rbac, subscription, topBanner, appleRestriction) |
providers/iblai-providers.tsx | Provider chain: ReduxProvider > SubscriptionConfigProvider > AuthProvider > TenantProvider, plus the data layer's error handlers: an expired session goes through the sign-in app's /login/complete and comes back signed in, a 401 it cannot recover goes back to the login page, a credits 402 is dispatched as the creditsexhausted DOM event and an admin's next step is /admin/billing |
next.config.ts -- webpack resolve.alias to deduplicate @reduxjs/toolkit,
turbopack: {} for Next.js 16+. Without the dedup,
SDK components use a different ReactReduxContext and RTK Query hooks silently
return undefined with zero HTTP requests.globals.css -- SDK base styles import..env.local -- platform key (NEXT_PUBLIC_MAIN_TENANT_KEY) and, for
server-side platform calls, IBLAI_API_KEY.For production apps, consider moving the SSO callback outside the auth providers using Next.js route groups:
app/
├── (auth)/
│ └── sso-login-complete/page.tsx ← Outside providers (no AuthProvider wrapper)
└── (app)/
├── layout.tsx ← IblaiProviders wraps only this group
└── page.tsx
This prevents the SSO callback deadlock where AuthProvider blocks rendering
before tokens are stored. Step 3 places the callback at
app/sso-login-complete/ (flat, no route group) which works for simple apps.
For the route group pattern, see the vibe-starter reference app: https://github.com/iblai/base/tree/main/skills/start/iblai-vibe-ops-init/assets/vibe-starter
Every origin the app runs on — http://localhost:3000, the deployed URL, a
Tauri custom scheme — must be in the organization's allowed redirect
origins. Nothing in the app can fix this; ask your ibl.ai operator to add
the origin. Also check the org key is not main (the shared org) or a
placeholder — the starter renders an alert for those instead of looping.
The SDK calls /api/custom-domains?domain=localhost as part of platform detection.
This fails on localhost but is harmless -- the platform is resolved from
NEXT_PUBLIC_MAIN_TENANT_KEY in .env.local instead. You can safely ignore
this console error during local development.
@reduxjs/toolkit must be deduplicated in next.config.ts. Without the
webpack alias, the SDK's components use a different ReactReduxContext than
your app's StoreProvider, so RTK Query hooks silently return undefined.
Verify your next.config has:
config.resolve.alias['@reduxjs/toolkit'] = rtkDir;
The SSO callback page (app/sso-login-complete/page.tsx) must NOT be wrapped
by AuthProvider. If it is, AuthProvider detects "no tokens" and redirects
to login before the callback can store the tokens -- creating an infinite loop.
If this happens, use the route group pattern described above to separate the SSO callback from the authenticated routes.
Check that .env.local has NEXT_PUBLIC_MAIN_TENANT_KEY set. Without it,
the platform resolution falls back to custom-domain detection which fails on
localhost, leaving the app in a broken state.
After auth is set up, add more features using skills -- ask your AI assistant to use:
| Skill | What It Adds |
|---|---|
/iblai-vibe-agent-chat | In-process agent chat surface |
/iblai-vibe-profile | User profile dropdown + settings page |
/iblai-vibe-account | Account/organization settings page |
/iblai-vibe-analytics | Analytics dashboard page |
/iblai-vibe-notification | Notification bell + center page |
For a complete reference app with auth, navbar, and pages already wired: https://github.com/iblai/base/tree/main/skills/start/iblai-vibe-ops-init/assets/vibe-starter
Brand guidelines: BRAND.md
ARCHITECTURE=multi-org)Five moves, all with SDK pieces vibe-starter already imports — the full
version is providers/index.tsx in iblai/os:
Org in the URL — app/platform/[tenantKey]/…; read it with
useParams(); keep resolveAppTenant() for the default org.
Providers — TenantProvider currentTenant={stored} requestedTenant={fromRoute}
with saveUserTokens, saveUserTenants, saveCurrentTenant, saveTenant
implemented (the starter's iblai-providers.tsx already has them). Replace the
starter's single-org handleTenantSwitch, which re-authenticates into
resolveAppTenant(): hand the SDK's own (tenant, saveRedirect) to the switch of
move 3. The SDK moves a user holding exactly [main, X] to X, and any other
target leaves the loading screen up or loops through the sign-in. Add
onTenantMismatch that goes to / unless isTenantSwitchInProgress(), so a
route still naming another org lands on the user's own.
Switching — the profile dropdown's Organizations item
(UserProfileDropdown showOrganizationsLink, on by default) opens the
sign-in app's organization chooser (openTenantSwitcher({ authUrl, tenant })
from @iblai/iblai-js/web-utils); the user picks there and comes back
signed in to that organization. The sign-in writes the picked organization
to tenant but never to app_tenant, which resolveAppTenant() reads
first, so point it there on the way in, or the next page re-authenticates
into the old organization. In app/sso-login-complete/page.tsx, add to
the starter's <SsoLogin>:
onLoginSuccess={(data: Record<string, string>) => {
if (data.tenant) localStorage.setItem("app_tenant", data.tenant);
}}
To switch from code, handleTenantSwitch(org, { authUrl }) clears
storage, re-enters the SPA with tenant=, broadcasts to other tabs.
Anonymous per agent — in AuthProvider's middleware, for
^/platform/([^/]+)/([^/]+) fetch the agent's public settings
(useLazyGetMentorPublicSettingsQuery) and return false when
allow_anonymous or mentor_visibility === "viewable_by_anyone".
Landing path guard — the starter's safeRedirectPath
(resolveRedirectPath on SsoLogin) keeps the landing on this origin;
also reset to / when the path names an org other than the one just
authenticated (data.tenant).
Register every deployed origin as an allowed redirect origin, exactly as for a single-org app.
assets/auth-utils.ts (opens in a new tab)assets/config.ts (opens in a new tab)assets/home-page.tsx (opens in a new tab)assets/iblai-providers.tsx (opens in a new tab)assets/iblai-store.ts (opens in a new tab)assets/iblai-styles.css (opens in a new tab)assets/sso-login-complete-page.tsx (opens in a new tab)assets/storage-service.ts (opens in a new tab)assets/tenant.ts (opens in a new tab)references/auth-interface.md (opens in a new tab)test.json (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub iblai/base --plugin iblai-vibe166 skills in this plugin
/iblai-api-agent-accessManage role-based access to an ibl.ai agent via the platform API — list role policies, search users/groups, and grant/revoke editor, chat, or analytics_viewer roles for users, groups, and emails. Use when controlling who can edit, chat with, or view analytics for an agent./iblai-api-agent-auditRead an ibl.ai agent's audit log via the platform API — a who-changed-what trail filterable by action, actor email, and date range. Read-only. Use when investigating configuration changes to an agent./iblai-api-agent-chatSet up live chat with a deployed ibl.ai agent by wiring the hosted iblai-api-agent-chat MCP server into the project (.mcp.json / claude mcp add) using the .env Api-Token and a chosen agent's unique id, or by signing in from claude.ai, ChatGPT or Claude Desktop with only the URL. Use to enable runtime conversations with an agent, and to list or disconnect the apps a user has connected. The actual chatting then happens through the MCP server's tools.Other plugins' skills for the same job