Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(desktop): require account onboarding after desktop sign-in (#21596)

YuTengjing408b90291a80
diff --git a/.agents/skills/spa-routes/SKILL.md b/.agents/skills/spa-routes/SKILL.md
index 9bbe2bbac72..28dd0f97834 100644
--- a/.agents/skills/spa-routes/SKILL.md
+++ b/.agents/skills/spa-routes/SKILL.md
@@ -97,11 +97,11 @@ Each feature should:
## 3a. Shared desktop route definition and platform adapters
-| File | Role |
-| ---------------------------------- | --------------------------------------------------------------------------------------------------------------- |
-| `desktopRouter.shared.tsx` | Single source of truth for common paths, nesting, metadata, lazy imports, and prioritized route preload groups. |
-| `desktopRouter.config.tsx` | Thin Web adapter: mounts the common content tree at `/` and adds Web-only routes. |
-| `desktopRouter.config.desktop.tsx` | Thin Electron adapter: injects per-tab Home behavior, TabHost root stubs, and Electron-only onboarding. |
+| File | Role |
+| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
+| `desktopRouter.shared.tsx` | Single source of truth for common paths, nesting, metadata, lazy imports, and prioritized route preload groups. |
+| `desktopRouter.config.tsx` | Thin Web adapter: mounts the common content tree at `/` and adds Web-only routes. |
+| `desktopRouter.config.desktop.tsx` | Thin Electron adapter: injects per-tab Home behavior, TabHost root stubs, and the Electron-only `/desktop-onboarding` local setup. |
Add or remove common routes only in `desktopRouter.shared.tsx`, or in a subtree module it imports (`taskWorkspaceRoutes.tsx`, `workspaceSettingsRoutes.tsx` for the padded `/:slug/settings/*` tabs) — the shared file is over the 1200-line limit, so large subtrees move out instead of growing it. Add any new subtree module to `readRouterSources` in `desktopRouter.sync.test.tsx`. Keep `desktopRouter.sync.test.tsx` passing so path behavior, lazy boundaries, preload ownership, and the intentional platform differences remain verified.
diff --git a/apps/desktop/src/main/types/store.ts b/apps/desktop/src/main/types/store.ts
index f2e3f596d1e..18ebd290176 100644
--- a/apps/desktop/src/main/types/store.ts
+++ b/apps/desktop/src/main/types/store.ts
@@ -19,6 +19,10 @@ export interface ElectronMainStore {
* Explicit completion state for the multi-step desktop onboarding flow.
* Undefined preserves the legacy behavior for users who completed onboarding
* before this marker existed.
+ *
+ * This covers only the device's local first-run setup. It is not the
+ * account onboarding (`users.onboarding.finishedAt`): the renderer checks
+ * that after sign-in and sends unfinished accounts to `/onboarding`.
*/
desktopOnboardingCompleted?: boolean;
encryptedTokens: {
diff --git a/src/features/Onboarding/RouteLayout.tsx b/src/features/Onboarding/RouteLayout.tsx
new file mode 100644
index 00000000000..03f1b97aa85
--- /dev/null
+++ b/src/features/Onboarding/RouteLayout.tsx
@@ -0,0 +1,31 @@
+'use client';
+
+import { TITLE_BAR_HEIGHT } from '@lobechat/desktop-bridge';
+import { Flexbox } from '@lobehub/ui';
+import { memo } from 'react';
+import { Outlet } from 'react-router';
+
+import { isDesktop } from '@/const/version';
+import SimpleTitleBar from '@/features/Electron/titlebar/SimpleTitleBar';
+
+/**
+ * The Electron main window is frameless (`frame: false`). Without a title bar,
+ * `/onboarding` could not be dragged on macOS and would have no window
+ * controls on Windows/Linux, so Desktop wraps it like `/desktop-onboarding`.
+ */
+const OnboardingRouteLayout = memo(() => {
+ if (!isDesktop) return <Outlet />;
+
+ return (
+ <Flexbox height={'100%'} width={'100%'}>
+ <SimpleTitleBar />
+ <Flexbox height={`calc(100% - ${TITLE_BAR_HEIGHT}px)`} width={'100%'}>
+ <Outlet />
+ </Flexbox>
+ </Flexbox>
+ );
+});
+
+OnboardingRouteLayout.displayName = 'OnboardingRouteLayout';
+
+export default OnboardingRouteLayout;
diff --git a/src/features/Onboarding/steps/TelemetryStep.tsx b/src/features/Onboarding/steps/TelemetryStep.tsx
index 0425b3421c6..a15722add46 100644
--- a/src/features/Onboarding/steps/TelemetryStep.tsx
+++ b/src/features/Onboarding/steps/TelemetryStep.tsx
@@ -173,6 +173,7 @@ const TelemetryStep = memo<TelemetryStepProps>(({ onNext }) => {
style={{ color: cssVar.colorSuccess, flexShrink: 0 }}
/>
<Text fontSize={12} type="secondary">
+ {/* New window: Desktop hands it to the system browser, Web keeps onboarding progress */}
<Trans
i18nKey={'telemetry.agreement'}
ns={'onboarding'}
@@ -180,7 +181,9 @@ const TelemetryStep = memo<TelemetryStepProps>(({ onNext }) => {
privacy: (
<a
href={PRIVACY_URL}
+ rel="noopener noreferrer"
style={{ color: 'inherit', cursor: 'pointer', textDecoration: 'underline' }}
+ target="_blank"
>
{t('telemetry.terms')}
</a>
@@ -188,7 +191,9 @@ const TelemetryStep = memo<TelemetryStepProps>(({ onNext }) => {
terms: (
<a
href={TERMS_URL}
+ rel="noopener noreferrer"
style={{ color: 'inherit', cursor: 'pointer', textDecoration: 'underline' }}
+ target="_blank"
>
{t('telemetry.privacy')}
</a>
diff --git a/src/layout/GlobalProvider/useUserStateRedirect.test.ts b/src/layout/GlobalProvider/useUserStateRedirect.test.ts
index 4436d0bf7da..445f0dbb7ca 100644
--- a/src/layout/GlobalProvider/useUserStateRedirect.test.ts
+++ b/src/layout/GlobalProvider/useUserStateRedirect.test.ts
@@ -3,7 +3,11 @@ import { afterEach, describe, expect, it } from 'vitest';
import { type UserInitializationState } from '@/types/user';
-import { shouldDeferOnboardingRedirect, useWebUserStateRedirect } from './useUserStateRedirect';
+import {
+ getOnboardingRedirectUrl,
+ shouldDeferOnboardingRedirect,
+ useUserStateRedirect,
+} from './useUserStateRedirect';
describe('shouldDeferOnboardingRedirect', () => {
it('defers on invite routes so invited users can accept before onboarding', () => {
@@ -25,7 +29,7 @@ describe('shouldDeferOnboardingRedirect', () => {
});
});
-describe('useWebUserStateRedirect', () => {
+describe('useUserStateRedirect on Web', () => {
const originalLocation = window.location;
const openPage = (url: string) => {
@@ -49,7 +53,7 @@ describe('useWebUserStateRedirect', () => {
const bindingLink = '/verify-im?random_id=abcdefgh&im_type=telegram';
openPage(bindingLink);
- const { result } = renderHook(() => useWebUserStateRedirect());
+ const { result } = renderHook(() => useUserStateRedirect());
result.current(notOnboarded);
expect(window.location.href).toBe(`/onboarding?callbackUrl=${encodeURIComponent(bindingLink)}`);
@@ -59,7 +63,7 @@ describe('useWebUserStateRedirect', () => {
const bindingLink = '/verify-im?random_id=abcdefgh&im_type=telegram';
openPage(bindingLink);
- const { result } = renderHook(() => useWebUserStateRedirect());
+ const { result } = renderHook(() => useUserStateRedirect());
result.current(onboarded);
expect(window.location.href).toBe(bindingLink);
@@ -68,9 +72,74 @@ describe('useWebUserStateRedirect', () => {
it('still lets an un-onboarded user accept a workspace invite first', () => {
openPage('/invite/abc');
- const { result } = renderHook(() => useWebUserStateRedirect());
+ const { result } = renderHook(() => useUserStateRedirect());
result.current(notOnboarded);
expect(window.location.href).toBe('/invite/abc');
});
});
+
+describe('getOnboardingRedirectUrl', () => {
+ const unfinished = { onboarding: { currentStep: 2, version: 1 } };
+ const finished = { onboarding: { currentStep: 5, finishedAt: '2026-10-01', version: 1 } };
+
+ it('sends a Desktop user whose account onboarding is unfinished to /onboarding', () => {
+ // Started onboarding on Web, closed the tab, then signed in through Desktop:
+ // the main window must not open until account onboarding finishes.
+ expect(
+ getOnboardingRedirectUrl({
+ isDesktopRuntime: true,
+ pathname: '/',
+ search: '',
+ state: unfinished,
+ }),
+ ).toBe('/onboarding');
+ });
+
+ it('keeps the Desktop page the user was opening as the post-onboarding target', () => {
+ expect(
+ getOnboardingRedirectUrl({
+ isDesktopRuntime: true,
+ pathname: '/agent/inbox',
+ search: '?topic=1',
+ state: unfinished,
+ }),
+ ).toBe(`/onboarding?callbackUrl=${encodeURIComponent('/agent/inbox?topic=1')}`);
+ });
+
+ it('lets Desktop local first-run setup finish before account onboarding', () => {
+ expect(
+ getOnboardingRedirectUrl({
+ isDesktopRuntime: true,
+ pathname: '/desktop-onboarding',
+ search: '?screen=login',
+ state: unfinished,
+ }),
+ ).toBeUndefined();
+ });
+
+ it('opens the Desktop main window once account onboarding is finished', () => {
+ expect(
+ getOnboardingRedirectUrl({
+ isDesktopRuntime: true,
+ pathname: '/',
+ search: '',
+ state: finished,
+ }),
+ ).toBeUndefined();
+ });
+
+ it('keeps the existing Web redirect', () => {
+ expect(
+ getOnboardingRedirectUrl({ isDesktopRuntime: false, pathname: '/', search: '', state: {} }),
+ ).toBe('/onboarding');
+ expect(
+ getOnboardingRedirectUrl({
+ isDesktopRuntime: false,
+ pathname: '/onboarding',
+ search: '',
+ state: unfinished,
+ }),
+ ).toBeUndefined();
+ });
+});
diff --git a/src/layout/GlobalProvider/useUserStateRedirect.ts b/src/layout/GlobalProvider/useUserStateRedirect.ts
index 916a52f0b8d..6689b5c1947 100644
--- a/src/layout/GlobalProvider/useUserStateRedirect.ts
+++ b/src/layout/GlobalProvider/useUserStateRedirect.ts
@@ -69,38 +69,53 @@ export const shouldDeferOnboardingRedirect = (pathname: string): boolean => {
return !!first && !RESERVED_FIRST_SEGMENTS.has(first);
};
-const redirectToOnboarding = (currentPath: string, search: string) => {
- if (!currentPath.startsWith('/onboarding')) {
- // Thread the page the user was on so onboarding finish points return there
- window.location.href = buildOnboardingRedirectUrl(currentPath + search);
- }
-};
+/**
+ * Desktop's local first-run setup (welcome, login, permissions, data mode).
+ * It runs before the account-level onboarding below and must not be
+ * interrupted once its login step fetches the user state.
+ */
+const DESKTOP_LOCAL_SETUP_PATH = '/desktop-onboarding';
-export const useDesktopUserStateRedirect = () => {
- // Desktop onboarding redirect is now handled by main process (BrowserManager)
- // No need to check localStorage here
- return useCallback(() => {}, []);
+interface OnboardingRedirectInput {
+ isDesktopRuntime: boolean;
+ pathname: string;
+ search: string;
+ state: Pick<UserInitializationState, 'onboarding'>;
+}
+
+/**
+ * Resolve where a user who has not finished account onboarding
+ * (`users.onboarding.finishedAt`) must go, or `undefined` to stay.
+ *
+ * Desktop applies the same account check as Web: its local setup
+ * (`desktopOnboardingCompleted` in the main process) only covers the device,
+ * so an account that signed in through the Desktop OIDC flow still has to
+ * finish `/onboarding` before using the main window.
+ */
+export const getOnboardingRedirectUrl = ({
+ isDesktopRuntime,
+ pathname,
+ search,
+ state,
+}: OnboardingRedirectInput): string | undefined => {
+ if (!onboardingSelectors.needsOnboarding(state)) return;
+ if (pathname.startsWith('/onboarding')) return;
+ if (isDesktopRuntime && isPathUnder(pathname, DESKTOP_LOCAL_SETUP_PATH)) return;
+ if (shouldDeferOnboardingRedirect(pathname)) return;
+
+ // Thread the page the user was on so onboarding finish points return there
+ return buildOnboardingRedirectUrl(pathname + search);
};
-export const useWebUserStateRedirect = () =>
+export const useUserStateRedirect = () =>
useCallback((state: UserInitializationState) => {
const { pathname, search } = window.location;
-
- if (!onboardingSelectors.needsOnboarding(state)) return;
- if (shouldDeferOnboardingRedirect(pathname)) return;
-
- redirectToOnboarding(pathname, search);
+ const redirectUrl = getOnboardingRedirectUrl({
+ isDesktopRuntime: isDesktop,
+ pathname,
+ search,
+ state,
+ });
+
+ if (redirectUrl) window.location.href = redirectUrl;
}, []);
-
-export const useUserStateRedirect = () => {
- const desktopRedirect = useDesktopUserStateRedirect();
- const webRedirect = useWebUserStateRedirect();
-
- return useCallback(
- (state: UserInitializationState) => {
- const redirect = isDesktop ? desktopRedirect : webRedirect;
- redirect(state);
- },
- [desktopRedirect, webRedirect],
- );
-};
diff --git a/src/routes/onboarding/_layout/index.tsx b/src/routes/onboarding/_layout/index.tsx
new file mode 100644
index 00000000000..283b8a3a13d
--- /dev/null
+++ b/src/routes/onboarding/_layout/index.tsx
@@ -0,0 +1 @@
+export { default } from '@/features/Onboarding/RouteLayout';
diff --git a/src/spa/router/desktopRouter.config.desktop.tsx b/src/spa/router/desktopRouter.config.desktop.tsx
index d9a2bd84f20..dd93eeeae33 100644
--- a/src/spa/router/desktopRouter.config.desktop.tsx
+++ b/src/spa/router/desktopRouter.config.desktop.tsx
@@ -38,12 +38,14 @@ export const desktopRoutes: RouteObject[] = createSharedDesktopRoutes({
{ element: null, index: true },
{ element: null, path: '*' },
],
- onboardingRoute: {
- element: dynamicElement(
- () => import('@/routes/(desktop)/desktop-onboarding'),
- 'Desktop > Desktop Onboarding',
- ),
- errorElement: <ErrorBoundary />,
- path: '/desktop-onboarding',
- },
+ platformRoutes: [
+ {
+ element: dynamicElement(
+ () => import('@/routes/(desktop)/desktop-onboarding'),
+ 'Desktop > Desktop Onboarding',
+ ),
+ errorElement: <ErrorBoundary />,
+ path: '/desktop-onboarding',
+ },
+ ],
});
diff --git a/src/spa/router/desktopRouter.config.tsx b/src/spa/router/desktopRouter.config.tsx
index f598ecf558b..5b0aa18c984 100644
--- a/src/spa/router/desktopRouter.config.tsx
+++ b/src/spa/router/desktopRouter.config.tsx
@@ -81,10 +81,5 @@ const webOnlyRoutes: RouteObject[] = [
export const desktopRoutes: RouteObject[] = createSharedDesktopRoutes({
mainAreaChildren: createMainAreaChildren(),
- onboardingRoute: {
- element: dynamicElement(() => import('@/routes/onboarding'), 'Desktop > Onboarding'),
- errorElement: <ErrorBoundary />,
- path: '/onboarding',
- },
platformRoutes: webOnlyRoutes,
});
diff --git a/src/spa/router/desktopRouter.shared.tsx b/src/spa/router/desktopRouter.shared.tsx
index 84e174dc6a7..2427e1a945d 100644
--- a/src/spa/router/desktopRouter.shared.tsx
+++ b/src/spa/router/desktopRouter.shared.tsx
@@ -64,6 +64,7 @@ import { agentChatTopicListLoader } from '@/spa/router/agentChatTopicListLoader'
import { agentDocumentListLoader } from '@/spa/router/agentDocumentListLoader';
import { channelDataLoader } from '@/spa/router/channelDataLoader';
import { identitiesListLoader } from '@/spa/router/identitiesListLoader';
+import { onboardingRoute } from '@/spa/router/onboardingRoute';
import { pageListLoader } from '@/spa/router/pageListLoader';
import { preferenceListLoader } from '@/spa/router/preferenceListLoader';
import { projectWorkspaceRoute } from '@/spa/router/projectWorkspaceRoutes';
@@ -1205,18 +1206,16 @@ export const createMainAreaRouteFactory = (options: MainAreaRouteOptions = {}) =
export interface SharedDesktopRouteOptions {
mainAreaChildren: RouteObject[];
- onboardingRoute: RouteObject;
- /** Routes that intentionally exist on only one runtime, such as Web `/verify-im`. */
+ /** Runtime-only routes, such as Web `/verify-im` or Electron `/desktop-onboarding`. */
platformRoutes?: RouteObject[];
}
/**
* Builds the common Web/Electron top-level route tree. Platform entry files
- * supply only the root children, runtime-only routes, and onboarding route.
+ * supply only the root children and runtime-only routes.
*/
export const createSharedDesktopRoutes = ({
mainAreaChildren,
- onboardingRoute,
platformRoutes = [],
}: SharedDesktopRouteOptions): RouteObject[] => [
{
diff --git a/src/spa/router/desktopRouter.sync.test.tsx b/src/spa/router/desktopRouter.sync.test.tsx
index fc0eb46eea9..fcb26e6174b 100644
--- a/src/spa/router/desktopRouter.sync.test.tsx
+++ b/src/spa/router/desktopRouter.sync.test.tsx
@@ -83,6 +83,7 @@ async function readRouterSources() {
'taskWorkspaceRoutes.tsx',
'workspaceSettingsRoutes.tsx',
'resourceRoutes.tsx',
+ 'onboardingRoute.tsx',
].map((filename) => readFile(path.join(process.cwd(), 'src/spa/router', filename), 'utf8')),
);
}
@@ -382,7 +383,8 @@ describe('desktop router shared definition', () => {
expect(electronPaths).not.toContain('/share/page');
expect(electronPaths).not.toContain('/verify');
expect(electronPaths).not.toContain('/acceptance');
- expect(electronPaths).not.toContain('/onboarding');
+ // Electron runs account onboarding after its local first-run setup.
+ expect(electronPaths).toContain('/onboarding');
expect(electronPaths).toContain('/desktop-onboarding');
});
diff --git a/src/spa/router/onboardingRoute.tsx b/src/spa/router/onboardingRoute.tsx
new file mode 100644
index 00000000000..4ec7d79e773
--- /dev/null
+++ b/src/spa/router/onboardingRoute.tsx
@@ -0,0 +1,23 @@
+import type { RouteObject } from 'react-router';
+
+import { dynamicElement, dynamicLayout, ErrorBoundary } from '@/utils/router';
+
+/**
+ * Account onboarding (`users.onboarding`), shared by Web and Electron.
+ * Electron enters it after its local `/desktop-onboarding` setup when the
+ * signed-in account has not finished it.
+ */
+export const onboardingRoute: RouteObject = {
+ children: [
+ {
+ element: dynamicElement(() => import('@/routes/onboarding'), 'Desktop > Onboarding'),
+ index: true,
+ },
+ ],
+ element: dynamicLayout(
+ () => import('@/routes/onboarding/_layout'),
+ 'Desktop > Onboarding > Layout',
+ ),
+ errorElement: <ErrorBoundary />,
+ path: '/onboarding',
+};