diff --git a/web/app/page.tsx b/web/app/page.tsx index 117d6c838d..ddb49655d3 100644 --- a/web/app/page.tsx +++ b/web/app/page.tsx @@ -1,7 +1,24 @@ -import Link from 'next/link' -import Loading from '@/app/components/base/loading' +'use client' + +import Link from 'next/link' +import { useRouter } from 'next/navigation' +import { useEffect } from 'react' +import Loading from '@/app/components/base/loading' +import { OAUTH_AUTHORIZE_PENDING_KEY } from '@/app/account/oauth/authorize/constants' +import { getOAuthPendingRedirect } from '@/app/signin/utils/post-login-redirect' + +const Home = () => { + const router = useRouter() + + useEffect(() => { + const pendingRedirect = getOAuthPendingRedirect(OAUTH_AUTHORIZE_PENDING_KEY) + if (pendingRedirect) { + router.replace(pendingRedirect) + return + } + router.replace('/apps') + }, [router]) -const Home = async () => { return (
diff --git a/web/app/signin/utils/post-login-redirect.ts b/web/app/signin/utils/post-login-redirect.ts index b548a1bac9..5b455cd1d1 100644 --- a/web/app/signin/utils/post-login-redirect.ts +++ b/web/app/signin/utils/post-login-redirect.ts @@ -2,7 +2,7 @@ import type { ReadonlyURLSearchParams } from 'next/navigation' import dayjs from 'dayjs' import { OAUTH_AUTHORIZE_PENDING_KEY, REDIRECT_URL_KEY } from '@/app/account/oauth/authorize/constants' -function getItemWithExpiry(key: string): string | null { +export function getOAuthPendingRedirect(key: string): string | null { const itemStr = localStorage.getItem(key) if (!itemStr) return null @@ -33,5 +33,5 @@ export const resolvePostLoginRedirect = (searchParams: ReadonlyURLSearchParams) } } - return getItemWithExpiry(OAUTH_AUTHORIZE_PENDING_KEY) + return getOAuthPendingRedirect(OAUTH_AUTHORIZE_PENDING_KEY) }