diff --git a/apps/studio/pages/sign-in-vercel-marketplace-v2.tsx b/apps/studio/pages/sign-in-vercel-marketplace-v2.tsx deleted file mode 100644 index a1747cde6d5..00000000000 --- a/apps/studio/pages/sign-in-vercel-marketplace-v2.tsx +++ /dev/null @@ -1,217 +0,0 @@ -import { useEffect, useState } from 'react' -import toast from 'react-hot-toast' -import * as Sentry from '@sentry/nextjs' - -import { useRouter } from 'next/router' -import { useIsLoggedIn, useUser } from 'common' -import Image from 'next/image' -import Link from 'next/link' -import { useTheme } from 'next-themes' -import { Button } from 'ui' -import { get } from 'data/fetchers' -import { getDisplayName } from 'components/interfaces/Auth/Users/UserListItem.utils' - -type VercelAuthState = 'invalid_code' - -const SignInVercelMarketplace = () => { - const { resolvedTheme } = useTheme() - const [loading, setLoading] = useState(false) - const [status, setStatus] = useState(null) - const isLoggedIn = useIsLoggedIn() - const router = useRouter() - const user = useUser() - - useEffect(() => { - if (!isLoggedIn) { - return - } - - async function verifyVercelIdentity() { - setLoading(true) - // @ts-ignore Kamil: no types regenerated for this, as this is just hacking around different authentication flows - const response = await get(`/partners/vercel/identity/verify`, { - params: { - query: { - code: router.query.code, - }, - }, - }).finally(async () => { - // TODO: Remove this. For demo purposes only. - await new Promise((resolve) => setTimeout(resolve, 1000)) - setLoading(false) - }) - - // if (response.response.status === 200) { - // if (router.query.resource_id) { - // router.push(`/project/${router.query.resource_id}`) - // } else { - // router.push(`/projects`) - // } - // return - // } - - if (response.response.status === 400) { - setStatus('invalid_code') - } - } - - verifyVercelIdentity() - }, [isLoggedIn, router]) - - // Flow without invites/approvals for now. - // - // Is user signed in? - // NO: - // - [x] if code is missing in query params, ask users to go through Vercel Dashboard; - // - [x] write an explanation that they need to login or sign-up; - // - [x] create 2 buttons that redirect to dashboard and preserve query string (it might be difficult for sign-up as it requires email confirmation); - // - [x] after login, redirect back to this page and perform [YES] flow; - // - [x] if code is missing in query params, ask users to go through Vercel Dashboard - // YES: - // - send API request to validate that user has provided identity assigned to this account - // - if yes, we are done - redirect to dashboard using provided `resource_id` if present or projects list if not - // - if not, write explainer that someone is signed with an account that is not linked with this Vercel user - // - they need to either login to a different account or they can link this account as well(???) - // - if there is no identity linked yet, show prompt to confirm account linking and perform API call to link accounts if they do so - // - on successful linking, redirect to the dashboard using provided `resource_id` if present or projects list if not - - // TODO(kamil): Sign-up link do not preserve query strings which we need to redirect after successful sign-up. - // This might not be needed if we won't get pop-up flow available anyway. - async function onSignInWithVercelMarketplace() { - if (isLoggedIn) { - // @ts-ignore - this is - const { response } = await get(`/partners/vercel/identity/verify`, { - params: { - query: { - ...router.query, - }, - }, - }) - - console.log({ response }) - } else { - try { - router.push({ - pathname: 'sign-in', - query: { - ...router.query, - returnTo: 'sign-in-vercel-marketplace', - }, - }) - // router.push(vercel_resource_id ? `/project/${vercel_resource_id}` : `/projects`) - } catch (error: any) { - toast.error(`Failed to sign in via Vercel Marketplace: ${error.message}`) - Sentry.captureMessage( - '[CRITICAL] Failed to sign in via Vercel Marketplace: ' + error.message - ) - setLoading(false) - } - } - } - - return ( -
-
- -
- {!router.query.code && ( -

- A SSO exchange code is required to login. -
- Go back to Vercel Marketplace and try again. -

- )} - {router.query.code && - (isLoggedIn ? ( - <> -
-

Logged in as {getDisplayName(user!, user!.email)}

- {loading ? ( -

Verifying linked account...

- ) : ( -
- {status === 'invalid_code' && ( -

- Invalid SSO exchange code. -
- Go back to Vercel Marketplace and try again. -

- )} - -
- )} - {/* CASE 1: This account is not linked anywhere, show "link account" button and redirect afterwards */} - {/* CASE 2: This account is correctly linked and we can automatically redirect (show button for now) */} - {/* CASE 3: This account is already linked to other account, show logout button and tell to login with different account */} -
- - ) : ( -
-

Sign In to Continue

-

- You need to be logged in on order to continue. -
- Don't have an account?{' '} - - Sign Up Now - {' '} - and login -
- via Vercel Marketplace to link your accounts. -

-
- -
-
- ))} -
- ) -} - -export default SignInVercelMarketplace diff --git a/apps/studio/pages/sign-in-vercel-marketplace.tsx b/apps/studio/pages/sign-in-vercel-marketplace.tsx deleted file mode 100644 index d9541b97bf0..00000000000 --- a/apps/studio/pages/sign-in-vercel-marketplace.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { useEffect, useState } from 'react' -import toast from 'react-hot-toast' -import * as Sentry from '@sentry/nextjs' - -import { auth } from 'lib/gotrue' -import { useRouter } from 'next/router' -import { useIsLoggedIn } from 'common' -import Image from 'next/image' -import Link from 'next/link' -import { useTheme } from 'next-themes' -import { Button } from 'ui' - -const SignInVercelMarketplace = () => { - const { resolvedTheme } = useTheme() - const [loading, setLoading] = useState(false) - const [isRedirecting, setIsRedirecting] = useState(false) - const isLoggedIn = useIsLoggedIn() - const router = useRouter() - const { - isReady, - query: { vercel_id_token, vercel_resource_id }, - } = router - - useEffect(() => { - if (!isReady) { - return - } - - async function onSignInWithVercelMarketplace() { - try { - if (!vercel_id_token) { - throw new Error('missing required id_token query param') - } - - setLoading(true) - const { error } = await auth.signInWithIdToken({ - token: vercel_id_token as string, - provider: 'vercel_marketplace', - }) - - if (error) { - throw error - } - - setIsRedirecting(true) - router.push(vercel_resource_id ? `/project/${vercel_resource_id}` : `/projects`) - } catch (error: any) { - toast.error(`Failed to sign in via Vercel Marketplace: ${error.message}`) - Sentry.captureMessage( - '[CRITICAL] Failed to sign in via Vercel Marketplace: ' + error.message - ) - setLoading(false) - setIsRedirecting(false) - } - } - - onSignInWithVercelMarketplace() - }, [router, isReady, vercel_resource_id, vercel_id_token]) - - return ( -
-
- -
-
-

Continue to Supabase Dashboard

-
- {loading &&

Checking your access rights...

} -
- ) -} - -export default SignInVercelMarketplace