Skip to content
Clone

feat(web/auth): land on the workspace right after a successful sign-in

The success screen used to wait only when a callback_url was present, so a plain
login sat there forever. Fall back to /app/@me and shorten the dwell time to
400ms, which keeps the confirmation visible while staying inside the one-second
budget. An explicit callback_url still wins.
ZhenYi committed
parent e874254 commit b2ab8a5 Browse files

1 file changed

+12 −6

Modified view/auth/src/pages/account/ui/account-page.tsx View view/auth/src/pages/account/ui/account-page.tsx
@@ -1,24 +1,30 @@
11import { CircleCheck } from 'lucide-react'
22import { useEffect } from 'react'
3import { useNavigate } from 'react-router-dom'
34import { callbackUrl, clearCallbackUrl } from '@/entities/auth-callback'
45import { useSession } from '@/entities/session'
56import { routes } from '@/shared/config'
67import { t } from '@/shared/i18n'
7import { navigate } from '@/shared/lib'
88import { Alert, Heading, SessionCheck } from '@/shared/ui'
99
10const CALLBACK_REDIRECT_DELAY_MS = 1000
10/// 登录成功后的停留时间:既要让用户看见成功态,又要保证 1 秒内进入工作台。
11const SUCCESS_REDIRECT_DELAY_MS = 400
1112
13/// 没有回跳地址时的默认落点。
14const DEFAULT_SUCCESS_TARGET = '/app/@me'
15
1216export function AccountPage() {
13 const { user, loading, task } = useSession({ onUnauthenticated: () => navigate(routes.login, true) })
17 const navigate = useNavigate()
18 const { user, loading, task } = useSession({
19 onUnauthenticated: () => navigate(routes.login, { replace: true }),
20 })
1421 useEffect(() => {
1522 if (!user) return
16 const target = callbackUrl.get()
17 if (!target) return
23 const target = callbackUrl.get() || DEFAULT_SUCCESS_TARGET
1824 const timer = setTimeout(() => {
1925 clearCallbackUrl()
2026 location.replace(target)
21 }, CALLBACK_REDIRECT_DELAY_MS)
27 }, SUCCESS_REDIRECT_DELAY_MS)
2228 return () => clearTimeout(timer)
2329 }, [user])
2430 if (loading || !user) return <SessionCheck loading={loading} notice={task.notice} onRetry={() => location.reload()} />