iblai-auth
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/iblai-auth
/iblai-auth
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.
Do NOT ask the user for their tenant key. The CLI
reads from automatically. If exists
with a real value, just run (no flag needed).
Otherwise use the placeholder:
PLATFORMiblai.enviblai.envPLATFORMiblai add authiblai add auth --platform your-platformIf already has set to a real
value (not a placeholder like , ,
, , , or empty), keep that value.
.env.localNEXT_PUBLIC_MAIN_TENANT_KEYyour-tenantyour-platformyour-tenant-keytest-tenantmainiblai.env.env.localDOMAINPLATFORMTOKEN.env.localUse as the default package manager. Fall back to if pnpm
is not installed. The generated app should live in the current directory,
not in a subdirectory.
pnpmnpm为原生Next.js应用添加ibl.ai SSO身份验证。配置完成后,未认证的用户会被重定向到login.iblai.app,登录完成后会带着会话返回应用,无需管理API令牌。
请勿向用户索要租户密钥。CLI会自动读取iblai.env中的变量。如果iblai.env存在且包含有效的值,只需运行(无需参数)。否则使用占位符形式:
PLATFORMPLATFORMiblai add authiblai add auth --platform your-platform如果中已经将设为有效值(不是、、、、这类占位符,也不是空值),请保留原有值。
.env.localNEXT_PUBLIC_MAIN_TENANT_KEYyour-tenantyour-platformyour-tenant-keytest-tenantmainiblai.env.env.localDOMAINPLATFORMTOKEN.env.local默认使用作为包管理器,如果未安装pnpm则回退到。生成的应用应当放在当前目录下,不要放在子目录中。
pnpmnpmPrerequisites
前置要求
Already have auth? If you used , auth is already
set up -- skip this skill.
iblai startapp agentWant a complete app from scratch? Create in a temp directory and copy back:
iblai startapp agent -o iblai-init
cp -a iblai-init/<app-name>/. . && rm -rf iblai-init
cp .env.example .env.local
pnpm install && pnpm devIf has , the CLI reads it automatically.
Otherwise pass .
iblai.envPLATFORM--platform your-platformThis skill is for adding auth to a vanilla Next.js app
() or an existing project.
npx create-next-app@latest my-app --yes- Next.js 14+ with App Router (directory)
app/ - Node.js 18+
- CLI available (
iblai)iblai --version
已经配置过认证? 如果你使用过命令,认证已经提前配置好了,可以跳过本教程。
iblai startapp agent想要从零搭建完整应用? 可以先在临时目录创建再复制回来:
iblai startapp agent -o iblai-init
cp -a iblai-init/<app-name>/. . && rm -rf iblai-init
cp .env.example .env.local
pnpm install && pnpm dev如果中存在变量,CLI会自动读取,否则需要传入参数。
iblai.envPLATFORM--platform your-platform本教程适用于为原生Next.js应用(通过创建)或现有项目添加认证。
npx create-next-app@latest my-app --yes- Next.js 14+ 版本,使用App Router(目录)
app/ - Node.js 18+ 版本
- 可用的CLI(可执行
iblai验证)iblai --version
Installing the CLI
安装CLI
If is not available:
iblaipip (recommended):
bash
pip install iblai-app-clinpx:
bash
npx @iblai/cli --version如果没有可用的命令:
iblaipip安装(推荐):
bash
pip install iblai-app-clinpx安装:
bash
npx @iblai/cli --versionUse npx @iblai/cli as prefix: npx @iblai/cli add auth --platform your-tenant
使用时添加npx @iblai/cli前缀:npx @iblai/cli add auth --platform your-tenant
**Build from source -- macOS / Linux** (Python 3.11+, pip, git, make):
```bash
git clone https://github.com/iblai/iblai-app-cli.git
cd iblai-app-cli
make -C .iblai install
cd - # back to your projectIf is not found after install, add to your PATH:
iblai~/.local/binbash
export PATH="$HOME/.local/bin:$PATH"To make permanent, add the line to or .
~/.bashrc~/.zshrcBuild from source -- Windows (Python 3.11+, pip, git):
powershell
git clone https://github.com/iblai/iblai-app-cli.git
cd iblai-app-cli
pip install -e .iblai/
cd -If is not found, ensure Python Scripts is in your PATH.
Typically at .
iblai%APPDATA%\Python\Python311\Scripts\
**从源码构建——macOS / Linux**(需要Python 3.11+、pip、git、make):
```bash
git clone https://github.com/iblai/iblai-app-cli.git
cd iblai-app-cli
make -C .iblai install
cd - # 回到你的项目目录如果安装后找不到命令,请将添加到PATH中:
iblai~/.local/binbash
export PATH="$HOME/.local/bin:$PATH"要永久生效,可将上述行添加到或文件中。
~/.bashrc~/.zshrc从源码构建——Windows(需要Python 3.11+、pip、git):
powershell
git clone https://github.com/iblai/iblai-app-cli.git
cd iblai-app-cli
pip install -e .iblai/
cd -如果找不到命令,请确认Python的Scripts目录已添加到PATH中,通常路径为。
iblai%APPDATA%\Python\Python311\Scripts\Step 0: Check for CLI Updates
步骤0:检查CLI更新
Before running any command, ensure the CLI is
up to date. Run to check the current version, then
upgrade directly:
iblaiiblai --version- pip:
pip install --upgrade iblai-app-cli - npm:
npm install -g @iblai/cli@latest
This is safe to run even if already at the latest version.
运行任何命令前,请确保CLI是最新版本。运行查看当前版本,然后直接升级:
iblaiiblai --version- pip方式:
pip install --upgrade iblai-app-cli - npm方式:
npm install -g @iblai/cli@latest
即使已经是最新版本,运行升级命令也是安全的。
Step 1: Check Environment
步骤1:检查环境
Before proceeding, check for a
in the project root. Look for , , and variables.
If the file does not exist or is missing these variables, tell the user:
"You need an with your platform configuration. Download the
template and fill in your values:
"
iblai.envPLATFORMDOMAINTOKENiblai.envcurl -o iblai.env https://raw.githubusercontent.com/iblai/vibe/refs/heads/main/iblai.envIf is set to a real value (not ), the CLI
will read it automatically — no flag needed in Step 3.
Otherwise use the placeholder.
PLATFORMyour-platform--platform继续操作前,请检查项目根目录是否存在文件,确认其中包含、和变量。如果文件不存在或者缺少这些变量,告知用户:
"你需要一个包含平台配置的文件。下载模板并填写你的配置:
"
iblai.envPLATFORMDOMAINTOKENiblai.envcurl -o iblai.env https://raw.githubusercontent.com/iblai/vibe/refs/heads/main/iblai.env如果设为有效值(不是),CLI会自动读取,步骤3无需添加参数,否则使用占位符形式。
PLATFORMyour-platform--platformStep 2: Customize Auth Interface
步骤2:自定义认证界面
STOP here. You MUST ask the user these questions before
proceeding to Step 3. Do NOT skip this step.
请在此处暂停。进入步骤3前,你必须先向用户确认以下问题,请勿跳过该步骤。
Fetch platform name
获取平台名称
First, read and from , then fetch the
platform metadata to get the platform name:
PLATFORMTOKENiblai.envbash
curl -s "https://api.{domain}/dm/api/core/orgs/{platform}/metadata/" \
-H "Authorization: Api-Token {token}"Use the field from the response as the auth title.
platform_name首先,从读取和,然后拉取平台元数据获取平台名称:
iblai.envPLATFORMTOKENbash
curl -s "https://api.{domain}/dm/api/core/orgs/{platform}/metadata/" \
-H "Authorization: Api-Token {token}"使用返回结果中的字段作为认证页面的标题。
platform_nameAsk the user
询问用户
Ask: "Briefly describe what your app does"
If the user skips or doesn't want to answer, use the platform name as
and leave empty. If the
user provides a description, generate a headline and tagline from it.
AUTH_DISPLAY_TITLEAUTH_DISPLAY_DESCRIPTIONUse as the default logo (favicon,
display logo, and side panel logo).
https://ibl.ai/images/iblai-logo.pngRemaining fields use fixed defaults:
- Footer credit — Always (the
"Powered by {{logo}}"placeholder renders the ibl.ai logo){{logo}} - Privacy policy URL — Always
"https://ibl.ai/privacy-policy" - Terms of use URL — Always
"https://ibl.ai/terms-of-use" - Display images — Leave empty ()
[] - Password-only login — Default
false
询问:"请简单描述你的应用功能"
如果用户跳过或者不想回答,使用平台名称作为,留空。如果用户提供了描述,基于该描述生成标题和标语。
AUTH_DISPLAY_TITLEAUTH_DISPLAY_DESCRIPTION使用作为默认logo(favicon、展示logo、侧边栏logo)。
https://ibl.ai/images/iblai-logo.png其余字段使用固定默认值:
- 页脚版权信息 —— 固定为(
"Powered by {{logo}}"占位符会渲染为ibl.ai的logo){{logo}} - 隐私政策链接 —— 固定为
"https://ibl.ai/privacy-policy" - 使用条款链接 —— 固定为
"https://ibl.ai/terms-of-use" - 展示图片 —— 留空()
[] - 仅密码登录 —— 默认
false
Save to iblai.env
iblai.env保存到iblai.env
iblai.envAfter generating the fields, append them to so the user can
review and edit before the API call:
iblai.envbash
undefined生成所有字段后,将它们追加到中,方便用户在调用API前查看和编辑:
iblai.envbash
undefinedAuth interface (edit before proceeding)
Auth interface (edit before proceeding)
AUTH_TITLE=<platform_name from API>
AUTH_LOGO=https://ibl.ai/images/iblai-logo.png
AUTH_DISPLAY_TITLE=<platform_name from API>
AUTH_DISPLAY_DESCRIPTION=
AUTH_FOOTER_CREDIT=Powered by {{logo}}
AUTH_PRIVACY_POLICY_URL=https://ibl.ai/privacy-policy
AUTH_TERMS_OF_USE_URL=https://ibl.ai/terms-of-use
AUTH_PASSWORD_ONLY=false
Tell the user: "I've saved the generated auth settings to `iblai.env`.
Review them and edit if needed, then let me know to continue."
STOP and wait for the user to confirm before proceeding with the API calls.
Re-read `iblai.env` to pick up any edits the user made.
After confirmation, use `PLATFORM` and `TOKEN` from `iblai.env` for all
API calls. All API requests use this header:Authorization: Api-Token <token>
undefinedAUTH_TITLE=<platform_name from API>
AUTH_LOGO=https://ibl.ai/images/iblai-logo.png
AUTH_DISPLAY_TITLE=<platform_name from API>
AUTH_DISPLAY_DESCRIPTION=
AUTH_FOOTER_CREDIT=Powered by {{logo}}
AUTH_PRIVACY_POLICY_URL=https://ibl.ai/privacy-policy
AUTH_TERMS_OF_USE_URL=https://ibl.ai/terms-of-use
AUTH_PASSWORD_ONLY=false
告知用户:"我已经将生成的认证配置保存到`iblai.env`中,请查看并按需编辑,完成后告知我继续操作。"
继续调用API前请暂停并等待用户确认,重新读取`iblai.env`获取用户修改后的配置。
确认后,所有API调用都使用`iblai.env`中的`PLATFORM`和`TOKEN`,所有API请求都携带以下请求头:Authorization: Api-Token <token>
undefinedUpload images first
优先上传图片
If is a local file path, upload it via:
AUTH_LOGObash
curl -X POST "https://api.{domain}/dm/api/core/platforms/{platform}/public-image-assets/" \
-H "Authorization: Api-Token {token}" \
-F "image=@{file_path}" \
-F "category={category}"Upload the logo three times with different categories. If is
already a URL (like the default), use it directly in the metadata payload
without uploading.
AUTH_LOGO| Image | Category |
|---|---|
| Favicon | |
| Display logo | |
| Side panel logo | |
| Display images (each) | |
The POST response returns a JSON object. Extract the field — that is
the URL to use in the metadata payload.
fileIf the user provided a URL (not a local file), use it directly in the
metadata payload without uploading.
如果是本地文件路径,通过以下接口上传:
AUTH_LOGObash
curl -X POST "https://api.{domain}/dm/api/core/platforms/{platform}/public-image-assets/" \
-H "Authorization: Api-Token {token}" \
-F "image=@{file_path}" \
-F "category={category}"logo需要上传3次,分别对应不同的分类。如果已经是URL(比如默认值),无需上传,直接在元数据请求体中使用该URL即可。
AUTH_LOGO| 图片类型 | 分类值 |
|---|---|
| Favicon | |
| 展示logo | |
| 侧边栏logo | |
| 展示图片(每张) | |
POST请求返回的JSON对象中,提取字段——该值就是元数据请求体中要使用的URL。
file如果用户提供的是URL(不是本地文件),无需上传,直接在元数据请求体中使用该URL即可。
PUT the metadata
提交元数据
After all images are uploaded, assemble the payload and PUT to:
PUT https://api.{domain}/dm/api/core/orgs/{platform}/metadata/
Authorization: Api-Token {token}
Content-Type: application/jsonThe payload has two identical keys — and
— both containing the same configuration:
auth_web_skillsaiauth_web_mentoraijson
{
"auth_web_skillsai": {
"title": "User's Title",
"favicon": "https://...uploaded-logo-url...",
"display_logo": "https://...uploaded-logo-url...",
"footer_credit": "Powered by {{logo}}",
"display_images": [],
"terms_of_use_url": "https://ibl.ai/terms-of-use",
"display_title_info": "Generated headline",
"privacy_policy_url": "https://ibl.ai/privacy-policy",
"display_description_info": "Generated description",
"display_slide_panel_logo": "https://...uploaded-logo-url...",
"authorize_only_password_login": false
},
"auth_web_mentorai": {
"title": "User's Title",
"favicon": "https://...uploaded-logo-url...",
"display_logo": "https://...uploaded-logo-url...",
"footer_credit": "Powered by {{logo}}",
"display_images": [],
"terms_of_use_url": "https://ibl.ai/terms-of-use",
"display_title_info": "Generated headline",
"privacy_policy_url": "https://ibl.ai/privacy-policy",
"display_description_info": "Generated description",
"display_slide_panel_logo": "https://...uploaded-logo-url...",
"authorize_only_password_login": false
}
}Always use ibl.ai's privacy policy and terms of use URLs. Generate the
headline and description from the user's app description. Set
to .
authorize_only_password_loginfalseAfter a successful PUT (200), tell the user: "Your login page has been
customized! Changes will appear on your next login at https://login.{domain}".
所有图片上传完成后,组装请求体,PUT到以下地址:
PUT https://api.{domain}/dm/api/core/orgs/{platform}/metadata/
Authorization: Api-Token {token}
Content-Type: application/json请求体包含两个相同的键——和,两者的配置完全一致:
auth_web_skillsaiauth_web_mentoraijson
{
"auth_web_skillsai": {
"title": "User's Title",
"favicon": "https://...uploaded-logo-url...",
"display_logo": "https://...uploaded-logo-url...",
"footer_credit": "Powered by {{logo}}",
"display_images": [],
"terms_of_use_url": "https://ibl.ai/terms-of-use",
"display_title_info": "Generated headline",
"privacy_policy_url": "https://ibl.ai/privacy-policy",
"display_description_info": "Generated description",
"display_slide_panel_logo": "https://...uploaded-logo-url...",
"authorize_only_password_login": false
},
"auth_web_mentorai": {
"title": "User's Title",
"favicon": "https://...uploaded-logo-url...",
"display_logo": "https://...uploaded-logo-url...",
"footer_credit": "Powered by {{logo}}",
"display_images": [],
"terms_of_use_url": "https://ibl.ai/terms-of-use",
"display_title_info": "Generated headline",
"privacy_policy_url": "https://ibl.ai/privacy-policy",
"display_description_info": "Generated description",
"display_slide_panel_logo": "https://...uploaded-logo-url...",
"authorize_only_password_login": false
}
}请始终使用ibl.ai的隐私政策和使用条款链接,基于用户的应用描述生成标题和描述,将设为。
authorize_only_password_loginfalsePUT请求成功(返回200)后,告知用户:"你的登录页面已经自定义完成!下次访问https://login.{domain}登录时就会看到更新后的效果。"
Step 3: Run the Generator
步骤3:运行生成器
bash
cd your-nextjs-appbash
cd your-nextjs-appIf iblai.env has PLATFORM, the CLI reads it automatically
如果iblai.env中存在PLATFORM,CLI会自动读取
iblai add auth
iblai add auth
Or pass explicitly (overrides iblai.env)
或者显式传入(会覆盖iblai.env中的配置)
iblai add auth --platform your-platform
iblai add auth --platform your-platform
Or via npx (when published)
或者通过npx运行(发布后可用)
npx @iblai/cli add auth --platform your-platform
The platform key sets `NEXT_PUBLIC_MAIN_TENANT_KEY` in `.env.local`.
The CLI reads `PLATFORM` from `iblai.env` automatically. Pass `--platform`
only if you want to override it or don't have an `iblai.env`.
The generator creates 7 files and patches `next.config`, `globals.css`, and `.env.local`.
It auto-detects `src/` directory layout and places files accordingly.npx @iblai/cli add auth --platform your-platform
平台密钥会设置到`.env.local`的`NEXT_PUBLIC_MAIN_TENANT_KEY`字段中。CLI会自动读取`iblai.env`中的`PLATFORM`,仅当你想要覆盖配置或者没有`iblai.env`文件时才需要传入`--platform`参数。
生成器会创建7个文件,并修改`next.config`、`globals.css`和`.env.local`文件,它会自动检测`src/`目录结构并将文件放到对应位置。Step 4: Install Dependencies
步骤4:安装依赖
bash
pnpm installThe generator adds these to :
package.json- -- SDK (auth, data layer, UI components)
@iblai/iblai-js - +
@reduxjs/toolkit-- state management (SDK uses RTK Query)react-redux - -- toast notifications
sonner - -- icons
lucide-react
bash
pnpm install生成器会在中添加以下依赖:
package.json- -- SDK(包含认证、数据层、UI组件)
@iblai/iblai-js - +
@reduxjs/toolkit-- 状态管理(SDK使用RTK Query)react-redux - -- 吐司通知
sonner - -- 图标
lucide-react
Step 5: Wire Providers into Layout
步骤5:在布局中引入Provider
Open and wrap with the generated .
app/layout.tsx{children}IblaiProvidersIf you have no existing providers:
tsx
import { IblaiProviders } from "@/providers/iblai-providers";
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):
tsx
import { IblaiProviders } from "@/providers/iblai-providers";
import { MyProvider } from "./my-provider";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<IblaiProviders>
<MyProvider>
{children}
</MyProvider>
</IblaiProviders>
</body>
</html>
);
}IblaiProviders打开,使用生成的包裹。
app/layout.tsxIblaiProviders{children}如果没有现有Provider:
tsx
import { IblaiProviders } from "@/providers/iblai-providers";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<IblaiProviders>{children}</IblaiProviders>
</body>
</html>
);
}如果有现有Provider(比如自定义context):
tsx
import { IblaiProviders } from "@/providers/iblai-providers";
import { MyProvider } from "./my-provider";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<IblaiProviders>
<MyProvider>
{children}
</MyProvider>
</IblaiProviders>
</body>
</html>
);
}IblaiProvidersStep 6: Configure Environment
步骤6:配置环境变量
If the CLI read from or you passed , the tenant key is already set in .
Verify with:
PLATFORMiblai.env--platform.env.localbash
iblai config showOtherwise, edit (created by the generator) or use the CLI:
.env.localbash
iblai config set NEXT_PUBLIC_MAIN_TENANT_KEY your-tenantThe default API URLs point to and are set automatically.
iblai.app如果CLI从读取了或者你传入了参数,租户密钥已经自动设置到中,可以通过以下命令验证:
iblai.envPLATFORM--platform.env.localbash
iblai config show否则,编辑生成器创建的文件,或者使用CLI设置:
.env.localbash
iblai config set NEXT_PUBLIC_MAIN_TENANT_KEY your-tenant默认的API地址指向,会自动设置。
iblai.appStep 7: Import SDK Styles
步骤7:导入SDK样式
Verify has the SDK imports (the generator patches this automatically):
app/globals.csscss
@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确认中已经导入了SDK样式(生成器会自动修改该文件):
app/globals.csscss
@import '@iblai/iblai-js/web-containers/styles';
@source "../node_modules/@iblai/iblai-js/dist/web-containers/source";如果缺少这些行,请将它们添加到的顶部附近。
globals.cssStep 8: Replace Default Home Page
步骤8:替换默认首页
After adding auth, check if still has the default Next.js
content (look for , , , or
). If it does, replace it with the ibl.ai home page:
app/page.tsxnext/imagevercel.svgVercelGet started by editingbash
iblai add homepageIf the user has already customized their home page, skip this step.
添加认证后,检查是否还保留Next.js默认内容(查找、、或者)。如果是,替换为ibl.ai首页:
app/page.tsxnext/imagevercel.svgVercelGet started by editingbash
iblai add homepage如果用户已经自定义过首页,可以跳过该步骤。
Step 9: Start Dev Server
步骤9:启动开发服务器
Start the dev server so the user can see the result:
bash
pnpm dev- Open http://localhost:3000
- You should be redirected to https://login.iblai.app
- Log in (or create a free account)
- You'll be returned to your app with a fully authenticated session
- Check browser localStorage -- you should see ,
axd_token,userDatatenants
启动开发服务器,让用户可以查看效果:
bash
pnpm dev- 打开 http://localhost:3000
- 你会被重定向到 https://login.iblai.app
- 登录(或者免费创建账号)
- 你会被带回你的应用,获得完整的认证会话
- 查看浏览器localStorage——你会看到、
axd_token、userData字段tenants
What Was Generated
生成的文件
| File | Purpose |
|---|---|
| SSO callback -- stores tokens from URL into localStorage |
| Environment variable accessors (API URLs, tenant key, auth URL) |
| localStorage wrapper implementing the SDK's StorageService interface |
| |
| Redux store with |
| Provider chain: ReduxProvider > AuthProvider > TenantProvider |
| 文件路径 | 用途 |
|---|---|
| SSO回调页面——将URL中的令牌存储到localStorage |
| 环境变量访问器(API地址、租户密钥、认证地址) |
| localStorage封装,实现SDK的StorageService接口 |
| 包含 |
| Redux store,包含 |
| Provider链:ReduxProvider > AuthProvider > TenantProvider |
What Was Patched
修改的文件
- -- webpack
next.config.tsto deduplicateresolve.alias,@reduxjs/toolkitfor Next.js 16+. Without the dedup, SDK components use a differentturbopack: {}and RTK Query hooks silently returnReactReduxContextwith zero HTTP requests.undefined - -- SDK base styles import.
globals.css - -- API URLs, auth URL, tenant key, WebSocket URL.
.env.local
- —— 添加webpack
next.config.ts配置去重resolve.alias,Next.js 16+版本添加@reduxjs/toolkit配置。如果没有去重,SDK组件会使用不同的turbopack: {},RTK Query钩子会静默返回ReactReduxContext,不会发起任何HTTP请求。undefined - —— 导入SDK基础样式。
globals.css - —— 添加API地址、认证地址、租户密钥、WebSocket地址。
.env.local
Advanced: Route Groups
进阶:路由分组
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.tsxThis prevents the SSO callback deadlock where blocks rendering
before tokens are stored. The generator places the callback at
(flat, no route group) which works for simple apps.
AuthProviderapp/sso-login-complete/For the route group pattern, see the reference implementation:
https://github.com/iblai/iblai-app-cli/tree/main/examples/iblai-agent-app
对于生产环境应用,建议使用Next.js路由分组将SSO回调页面移到认证Provider外部:
app/
├── (auth)/
│ └── sso-login-complete/page.tsx ← 在Provider外部(没有AuthProvider包裹)
└── (app)/
├── layout.tsx ← IblaiProviders仅包裹该分组
└── page.tsx这可以避免SSO回调死锁:即在令牌存储前就阻塞渲染。生成器默认将回调页面放在(平级,没有路由分组),可以满足简单应用的需求。
AuthProviderapp/sso-login-complete/关于路由分组模式,可以参考实现示例:
https://github.com/iblai/iblai-app-cli/tree/main/examples/iblai-agent-app
Troubleshooting
问题排查
"Unknown server error" with custom-domains on localhost
本地环境自定义域名出现"Unknown server error"
The SDK calls as part of tenant detection.
This fails on localhost but is harmless -- the tenant is resolved from
in instead. You can safely ignore
this console error during local development.
/api/custom-domains?domain=localhostNEXT_PUBLIC_MAIN_TENANT_KEY.env.localSDK会调用进行租户检测,该请求在本地环境会失败,但无影响——租户会转而从的字段解析。本地开发时可以忽略该控制台错误。
/api/custom-domains?domain=localhost.env.localNEXT_PUBLIC_MAIN_TENANT_KEYSDK components show undefined / no API requests
SDK组件显示undefined / 没有API请求
@reduxjs/toolkitnext.config.tsReactReduxContextStoreProviderundefinedVerify your next.config has:
javascript
config.resolve.alias['@reduxjs/toolkit'] = rtkDir;@reduxjs/toolkitnext.config.tsStoreProviderReactReduxContextundefined确认你的next.config包含以下配置:
javascript
config.resolve.alias['@reduxjs/toolkit'] = rtkDir;Auth redirect loops
认证重定向循环
The SSO callback page () must NOT be wrapped
by . If it is, detects "no tokens" and redirects
to login before the callback can store the tokens -- creating an infinite loop.
app/sso-login-complete/page.tsxAuthProviderAuthProviderIf this happens, use the route group pattern described above to separate the
SSO callback from the authenticated routes.
SSO回调页面()不能被包裹。如果被包裹,会检测到"无令牌",在回调存储令牌前就重定向到登录页,造成无限循环。
app/sso-login-complete/page.tsxAuthProviderAuthProvider如果出现该问题,使用上面提到的路由分组模式,将SSO回调和认证路由分开。
Blank screen after login
登录后页面空白
Check that has set. Without it,
the tenant resolution falls back to custom-domain detection which fails on
localhost, leaving the app in a broken state.
.env.localNEXT_PUBLIC_MAIN_TENANT_KEY检查是否设置了。如果没有,租户解析会回退到自定义域名检测,在本地环境会失败,导致应用处于异常状态。
.env.localNEXT_PUBLIC_MAIN_TENANT_KEYNext Steps
后续步骤
After auth is set up, add more features:
bash
iblai add chat # AI chat widget (requires agent ID)Other features are built using skills -- ask your AI assistant to use:
| Skill | What It Adds |
|---|---|
| AI chat widget |
| User profile dropdown + settings page |
| Account/organization settings page |
| Analytics dashboard page |
| Notification bell + center page |
For the complete reference implementation with all features:
https://github.com/iblai/iblai-app-cli/tree/main/examples/iblai-agent-app
Brand guidelines: BRAND.md
认证配置完成后,可以添加更多功能:
bash
iblai add chat # AI聊天组件(需要agent ID)其他功能可以通过skill实现——告知你的AI助手使用以下skill:
| Skill | 添加的功能 |
|---|---|
| AI聊天组件 |
| 用户头像下拉菜单 + 设置页 |
| 账号/组织设置页 |
| 数据分析看板页 |
| 通知铃铛 + 通知中心页 |
品牌指南: BRAND.md