diff --git a/studio/components/interfaces/App/RouteValidationWrapper.tsx b/studio/components/interfaces/App/RouteValidationWrapper.tsx index 39441b63a05..a0cac70e50f 100644 --- a/studio/components/interfaces/App/RouteValidationWrapper.tsx +++ b/studio/components/interfaces/App/RouteValidationWrapper.tsx @@ -23,7 +23,7 @@ const RouteValidationWrapper: FC = ({ children }) => { // or prompt the user to create an organaization // this is used by database.dev, usually as /new/new-project '/new/[slug]', - '/org/[slug]/join', + '/join', ] /** diff --git a/studio/pages/join/index.tsx b/studio/pages/join/index.tsx index 315f250381d..c16000f9778 100644 --- a/studio/pages/join/index.tsx +++ b/studio/pages/join/index.tsx @@ -8,7 +8,7 @@ import { API_URL } from 'lib/constants' import { get, post, delete_ } from 'lib/common/fetch' import { useEffect } from 'react' -interface TokenInfo { +interface TokenInfoI { organization_name: string | undefined token_does_not_exist: boolean email_match: boolean @@ -17,12 +17,14 @@ interface TokenInfo { invite_id: number } +type TokenInfo = TokenInfoI | undefined + const User = () => { const router = useRouter() const { slug, token } = router.query const { ui } = useStore() const [isSubmitting, setIsSubmitting] = useState(false) - const [tokenValidationInfo, setTokenValidationInfo] = useState() + const [tokenValidationInfo, setTokenValidationInfo] = useState(undefined) const [tokenInfoLoaded, setTokenInfoLoaded] = useState(false) const { token_does_not_exist, @@ -33,30 +35,21 @@ const User = () => { invite_id, } = tokenValidationInfo || {} - console.log(slug, token) - console.log('tokenValidationInfo', tokenValidationInfo) - console.log('tokenInfoLoaded', tokenInfoLoaded) - useEffect(() => { - let cancel = false - async function fetchTokenInfo() { - const response = await get(`${API_URL}/organizations/${slug}/members/join?token=${token}`, {}) - if (!cancel) { + try { + const response = await get(`${API_URL}/organizations/${slug}/members/join?token=${token}`) setTokenValidationInfo(response) setTokenInfoLoaded(true) + } catch (error) { + console.error(error) } } - if (router.query.token) { - console.log('i have a tokens') + if (router.query.token && !tokenInfoLoaded) { fetchTokenInfo() } - - return () => { - cancel = true - } - }, []) + }, [router.query]) async function handleJoinOrganization() { setIsSubmitting(true) @@ -93,32 +86,23 @@ const User = () => { } return ( -
- {/* - - */} - - - Supabase - {/*

Supabase

*/} -
- - +
+ + + Supabase + {/*

Supabase

*/} +
+

Join {organization_name && email_match ? organization_name : 'a new organization'}

@@ -136,8 +120,8 @@ const User = () => { )}
-
-
+
+
{authorized_user && !expired_token && email_match && tokenInfoLoaded && (
+ + +
+ )} + {!authorized_user && ( +
+ + + +
+ )}