diff --git a/src/app/(centered)/authorized/Authorized.tsx b/src/app/(centered)/authorized/Authorized.tsx index 2a01aa40e4..dc1fa67a05 100644 --- a/src/app/(centered)/authorized/Authorized.tsx +++ b/src/app/(centered)/authorized/Authorized.tsx @@ -1,6 +1,7 @@ 'use client'; import { useState, useRef, useEffect } from 'react'; +import { useSessionStorage } from 'react-use'; import { useRouter } from 'next/navigation'; import { useAuth } from '@clerk/nextjs'; import { LoaderCircle, CircleCheck, CircleX } from 'lucide-react'; @@ -12,6 +13,7 @@ export const Authorized = () => { const [isLoading, setIsLoading] = useState(true); const isLoadingRef = useRef(true); const router = useRouter(); + const [state, setState] = useSessionStorage('state'); useEffect(() => { if (typeof isSignedIn !== 'undefined' && isLoadingRef.current) { @@ -22,17 +24,19 @@ export const Authorized = () => { useEffect(() => { if (!isLoading) { - let path = '/dashboard'; + let path; if (!isSignedIn) { - path = '/sign-in'; + path = state ? `/sign-in?state=${state}` : '/sign-in'; } else if (!orgId) { - path = '/select-org'; + path = state ? `/select-org/${state}` : '/select-org'; + } else { + path = state ? `/extension/sign-in?state=${state}` : '/dashboard'; } setTimeout(() => router.push(path), 1000); } - }, [router, isLoading, isSignedIn, orgId]); + }, [router, isLoading, isSignedIn, orgId, state, setState]); return ( diff --git a/src/app/(centered)/authorized/[[...state]]/Authorized.tsx b/src/app/(centered)/authorized/[[...state]]/Authorized.tsx deleted file mode 100644 index dc1fa67a05..0000000000 --- a/src/app/(centered)/authorized/[[...state]]/Authorized.tsx +++ /dev/null @@ -1,59 +0,0 @@ -'use client'; - -import { useState, useRef, useEffect } from 'react'; -import { useSessionStorage } from 'react-use'; -import { useRouter } from 'next/navigation'; -import { useAuth } from '@clerk/nextjs'; -import { LoaderCircle, CircleCheck, CircleX } from 'lucide-react'; - -import { Card, CardContent } from '@/components/ui'; - -export const Authorized = () => { - const { isSignedIn, orgId } = useAuth(); - const [isLoading, setIsLoading] = useState(true); - const isLoadingRef = useRef(true); - const router = useRouter(); - const [state, setState] = useSessionStorage('state'); - - useEffect(() => { - if (typeof isSignedIn !== 'undefined' && isLoadingRef.current) { - isLoadingRef.current = false; - setTimeout(() => setIsLoading(false), 250); - } - }, [isSignedIn]); - - useEffect(() => { - if (!isLoading) { - let path; - - if (!isSignedIn) { - path = state ? `/sign-in?state=${state}` : '/sign-in'; - } else if (!orgId) { - path = state ? `/select-org/${state}` : '/select-org'; - } else { - path = state ? `/extension/sign-in?state=${state}` : '/dashboard'; - } - - setTimeout(() => router.push(path), 1000); - } - }, [router, isLoading, isSignedIn, orgId, state, setState]); - - return ( - - -
-
- Authenticating -
- {isLoading ? ( - - ) : isSignedIn ? ( - - ) : ( - - )} -
-
-
- ); -}; diff --git a/src/app/(centered)/authorized/[[...state]]/page.tsx b/src/app/(centered)/authorized/[[...state]]/page.tsx deleted file mode 100644 index 088db4ce91..0000000000 --- a/src/app/(centered)/authorized/[[...state]]/page.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { Authorized } from './Authorized'; - -export default function Page() { - return ; -} diff --git a/src/app/(centered)/authorized/page.tsx b/src/app/(centered)/authorized/page.tsx index 763b523c91..088db4ce91 100644 --- a/src/app/(centered)/authorized/page.tsx +++ b/src/app/(centered)/authorized/page.tsx @@ -1,5 +1,5 @@ import { Authorized } from './Authorized'; -export default async function Page() { +export default function Page() { return ; }