diff --git a/src/app/(authenticated)/extension/sign-in/DeepLink.tsx b/src/app/extension/sign-in/DeepLink.tsx similarity index 100% rename from src/app/(authenticated)/extension/sign-in/DeepLink.tsx rename to src/app/extension/sign-in/DeepLink.tsx diff --git a/src/app/(authenticated)/extension/sign-in/page.tsx b/src/app/extension/sign-in/page.tsx similarity index 78% rename from src/app/(authenticated)/extension/sign-in/page.tsx rename to src/app/extension/sign-in/page.tsx index 1aab66ee91..5f7e1fd52d 100644 --- a/src/app/(authenticated)/extension/sign-in/page.tsx +++ b/src/app/extension/sign-in/page.tsx @@ -9,19 +9,19 @@ import { DeepLink } from './DeepLink'; export default async function Page(params: { searchParams: { state?: string }; }) { - const { userId } = await auth(); + const { state } = await params.searchParams; - if (!userId) { - redirect('/sign-in'); + if (!state) { + redirect(`/sign-in`); } - const code = await getSignInToken(userId); + const { userId } = await auth(); + const code = userId ? await getSignInToken(userId) : undefined; if (!code) { - redirect('/sign-in'); + redirect(`/sign-in?state=${state}`); } - const { state = '' } = await params.searchParams; const searchParams = new URLSearchParams({ state, code }); const path = `/auth/clerk/callback?${searchParams.toString()}`; const vsCodeUrl = new URL(path, Env.VSCODE_EXTENSION_BASE_URL); diff --git a/src/app/sign-in/[[...sign-in]]/SignIn.tsx b/src/app/sign-in/[[...sign-in]]/SignIn.tsx index a12e84d7b9..068eb7e5cd 100644 --- a/src/app/sign-in/[[...sign-in]]/SignIn.tsx +++ b/src/app/sign-in/[[...sign-in]]/SignIn.tsx @@ -1,5 +1,7 @@ 'use client'; +import { useMemo } from 'react'; +import { useSearchParams } from 'next/navigation'; import Link from 'next/link'; import { useTheme } from 'next-themes'; import { dark } from '@clerk/themes'; @@ -10,13 +12,22 @@ import { Logo } from '@/components/layout'; export const SignIn = () => { const { resolvedTheme } = useTheme(); const baseTheme = resolvedTheme === 'dark' ? dark : undefined; + const searchParams = useSearchParams(); + + const forceRedirectUrl = useMemo(() => { + const state = searchParams.get('state'); + return state ? `/extension/sign-in?state=${state}` : undefined; + }, [searchParams]); return (
- +
); }; diff --git a/src/app/sign-up/[[...sign-up]]/SignUp.tsx b/src/app/sign-up/[[...sign-up]]/SignUp.tsx index 6e5b6d25f8..48c68094fb 100644 --- a/src/app/sign-up/[[...sign-up]]/SignUp.tsx +++ b/src/app/sign-up/[[...sign-up]]/SignUp.tsx @@ -1,5 +1,7 @@ 'use client'; +import { useMemo } from 'react'; +import { useSearchParams } from 'next/navigation'; import Link from 'next/link'; import { useTheme } from 'next-themes'; import { dark } from '@clerk/themes'; @@ -10,13 +12,22 @@ import { Logo } from '@/components/layout'; export const SignUp = () => { const { resolvedTheme } = useTheme(); const baseTheme = resolvedTheme === 'dark' ? dark : undefined; + const searchParams = useSearchParams(); + + const forceRedirectUrl = useMemo(() => { + const state = searchParams.get('state'); + return state ? `/extension/sign-in?state=${state}` : undefined; + }, [searchParams]); return (
- +
); };