🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(onboarding): redirect un-onboarded users on IM binding links (#21595)
YuTengjing296040647576
diff --git a/src/layout/GlobalProvider/useUserStateRedirect.test.ts b/src/layout/GlobalProvider/useUserStateRedirect.test.tsindex 412d07c362a..4436d0bf7da 100644--- a/src/layout/GlobalProvider/useUserStateRedirect.test.ts+++ b/src/layout/GlobalProvider/useUserStateRedirect.test.ts@@ -1,6 +1,9 @@-import { describe, expect, it } from 'vitest';+import { renderHook } from '@testing-library/react';+import { afterEach, describe, expect, it } from 'vitest';-import { shouldDeferOnboardingRedirect } from './useUserStateRedirect';+import { type UserInitializationState } from '@/types/user';++import { shouldDeferOnboardingRedirect, useWebUserStateRedirect } from './useUserStateRedirect';describe('shouldDeferOnboardingRedirect', () => {it('defers on invite routes so invited users can accept before onboarding', () => {@@ -18,5 +21,56 @@ describe('shouldDeferOnboardingRedirect', () => {expect(shouldDeferOnboardingRedirect('/agent')).toBe(false);expect(shouldDeferOnboardingRedirect('/projects')).toBe(false);expect(shouldDeferOnboardingRedirect('/settings/profile')).toBe(false);+ expect(shouldDeferOnboardingRedirect('/verify-im')).toBe(false);+ });+});++describe('useWebUserStateRedirect', () => {+ const originalLocation = window.location;++ const openPage = (url: string) => {+ const { pathname, search } = new URL(url, 'https://app.example.com');+ Object.defineProperty(window, 'location', {+ configurable: true,+ value: { href: url, pathname, search },+ });+ };++ const notOnboarded = { onboarding: { currentStep: 1, version: 1 } } as UserInitializationState;+ const onboarded = {+ onboarding: { currentStep: 1, finishedAt: '2026-01-01T00:00:00.000Z', version: 1 },+ } as UserInitializationState;++ afterEach(() => {+ Object.defineProperty(window, 'location', { configurable: true, value: originalLocation });+ });++ it('sends an un-onboarded user who opens an IM binding link to onboarding and back', () => {+ const bindingLink = '/verify-im?random_id=abcdefgh&im_type=telegram';+ openPage(bindingLink);++ const { result } = renderHook(() => useWebUserStateRedirect());+ result.current(notOnboarded);++ expect(window.location.href).toBe(`/onboarding?callbackUrl=${encodeURIComponent(bindingLink)}`);+ });++ it('lets an onboarded user stay on the IM binding page', () => {+ const bindingLink = '/verify-im?random_id=abcdefgh&im_type=telegram';+ openPage(bindingLink);++ const { result } = renderHook(() => useWebUserStateRedirect());+ result.current(onboarded);++ expect(window.location.href).toBe(bindingLink);+ });++ it('still lets an un-onboarded user accept a workspace invite first', () => {+ openPage('/invite/abc');++ const { result } = renderHook(() => useWebUserStateRedirect());+ result.current(notOnboarded);++ expect(window.location.href).toBe('/invite/abc');});});diff --git a/src/layout/GlobalProvider/useUserStateRedirect.ts b/src/layout/GlobalProvider/useUserStateRedirect.tsindex b4b6ef4c484..916a52f0b8d 100644--- a/src/layout/GlobalProvider/useUserStateRedirect.ts+++ b/src/layout/GlobalProvider/useUserStateRedirect.ts@@ -12,6 +12,9 @@ const DEFER_REDIRECT_PREFIXES = ['/invite'];// `/a/:slugOrId` (agent-share visitor page) is deliberately NOT listed: a// user who followed a share link should reach the shared agent, not be// bounced into onboarding first.+// `verify-im` must stay listed: binding an IM account lets that platform start+// agent runs, which an un-onboarded account cannot use, so the binding link+// detours through onboarding and returns via `callbackUrl`.const RESERVED_FIRST_SEGMENTS = new Set(['agent','apps',@@ -37,6 +40,7 @@ const RESERVED_FIRST_SEGMENTS = new Set(['subscription','task','tasks',+ 'verify-im','video',]);