The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: add enterprise login flow (#10269)
Stojan Dimitrovskib918a6922ca4
diff --git a/package-lock.json b/package-lock.jsonindex af611d55cdc..90d03886fa5 100644--- a/package-lock.json+++ b/package-lock.json@@ -9625,9 +9625,9 @@}},"node_modules/@supabase/gotrue-js": {- "version": "2.2.1",- "resolved": "https://registry.npmjs.org/@supabase/gotrue-js/-/gotrue-js-2.2.1.tgz",- "integrity": "sha512-CgQaYAJmGbOLPSqan4mjRgGikzsrlkKdPq0UNG7WZQv5HlHJlAYW8HeyNw/SKfIbxQBm8s2dBCeUyX+NdfB2Rw==",+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/@supabase/gotrue-js/-/gotrue-js-2.3.0.tgz",+ "integrity": "sha512-e50w8LkfbxtI2SJxUbuQNM7pN+Yu3HYkvCLsidwBgivTdcoFOkhFodwLvWSVdeaxY1mH6Gm66RiKeUMn1+BAow==","dependencies": {"cross-fetch": "^3.1.5"}@@ -9697,12 +9697,12 @@}},"node_modules/@supabase/supabase-js": {- "version": "2.0.4",- "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.0.4.tgz",- "integrity": "sha512-Z5uLyJm9bz5LMFnt5d1I6ccxVTdvKbJa0RsYGgKlA+QiyGvBxRRvVh8pqlYP1571DlycGG7bWngNwdv7/pehrg==",+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.1.0.tgz",+ "integrity": "sha512-hODrAUDSC6RV6EhwuSMyhaQCF32gij0EBTceuDR+8suJsg7XcyUG0fYgeYecWIvt0nz61xAMY6E+Ywb0tJaAng==","dependencies": {"@supabase/functions-js": "^2.0.0",- "@supabase/gotrue-js": "^2.2.0",+ "@supabase/gotrue-js": "^2.3.0","@supabase/postgrest-js": "^1.1.0","@supabase/realtime-js": "^2.1.0","@supabase/storage-js": "^2.0.0",@@ -37986,7 +37986,7 @@"@supabase/postgres-meta": "^0.26.1","@supabase/react-data-grid": "^7.1.0-beta.7","@supabase/shared-types": "^0.1.29",- "@supabase/supabase-js": "^2.0.0",+ "@supabase/supabase-js": "^2.1.0","ajv": "^8.6.3","analytics-node": "^3.5.0","awesome-debounce-promise": "^2.1.0",@@ -44857,9 +44857,9 @@}},"@supabase/gotrue-js": {- "version": "2.2.1",- "resolved": "https://registry.npmjs.org/@supabase/gotrue-js/-/gotrue-js-2.2.1.tgz",- "integrity": "sha512-CgQaYAJmGbOLPSqan4mjRgGikzsrlkKdPq0UNG7WZQv5HlHJlAYW8HeyNw/SKfIbxQBm8s2dBCeUyX+NdfB2Rw==",+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/@supabase/gotrue-js/-/gotrue-js-2.3.0.tgz",+ "integrity": "sha512-e50w8LkfbxtI2SJxUbuQNM7pN+Yu3HYkvCLsidwBgivTdcoFOkhFodwLvWSVdeaxY1mH6Gm66RiKeUMn1+BAow==","requires": {"cross-fetch": "^3.1.5"}@@ -44920,12 +44920,12 @@}},"@supabase/supabase-js": {- "version": "2.0.4",- "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.0.4.tgz",- "integrity": "sha512-Z5uLyJm9bz5LMFnt5d1I6ccxVTdvKbJa0RsYGgKlA+QiyGvBxRRvVh8pqlYP1571DlycGG7bWngNwdv7/pehrg==",+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.1.0.tgz",+ "integrity": "sha512-hODrAUDSC6RV6EhwuSMyhaQCF32gij0EBTceuDR+8suJsg7XcyUG0fYgeYecWIvt0nz61xAMY6E+Ywb0tJaAng==","requires": {"@supabase/functions-js": "^2.0.0",- "@supabase/gotrue-js": "^2.2.0",+ "@supabase/gotrue-js": "^2.3.0","@supabase/postgrest-js": "^1.1.0","@supabase/realtime-js": "^2.1.0","@supabase/storage-js": "^2.0.0",diff --git a/studio/components/interfaces/SignIn/SignInSSOForm.tsx b/studio/components/interfaces/SignIn/SignInSSOForm.tsxnew file mode 100644index 00000000000..874e0f6b97d--- /dev/null+++ b/studio/components/interfaces/SignIn/SignInSSOForm.tsx@@ -0,0 +1,108 @@+import HCaptcha from '@hcaptcha/react-hcaptcha'+import { useStore } from 'hooks'+import { auth } from 'lib/gotrue'+import { useRef, useState } from 'react'+import { useSWRConfig } from 'swr'+import { Button, Form, Input } from 'ui'+import { object, string } from 'yup'++const signInSchema = object({+ email: string().email('Must be a valid email').required('Email is required'),+})++const SignInSSOForm = () => {+ const { ui } = useStore()+ const { cache } = useSWRConfig()++ const [captchaToken, setCaptchaToken] = useState<string | null>(null)+ const captchaRef = useRef<HCaptcha>(null)++ const onSignIn = async ({ email, password }: { email: string; password: string }) => {+ const toastId = ui.setNotification({+ category: 'loading',+ message: `Signing in...`,+ })++ let token = captchaToken+ if (!token) {+ const captchaResponse = await captchaRef.current?.execute({ async: true })+ token = captchaResponse?.response ?? null+ }++ const { data, error } = await auth.signInWithSSO({+ domain: email.split('@')[1],+ options: { captchaToken: token ?? undefined },+ })++ if (!error) {+ // .clear() does actually exist on the cache object, but it's not in the types 🤦🏻+ // @ts-ignore+ cache.clear()++ if (data) {+ // redirect to SSO identity provider page+ window.location.href = data.url+ }+ } else {+ captchaRef.current?.resetCaptcha()++ ui.setNotification({+ id: toastId,+ category: 'error',+ message: error.message,+ })+ }+ }++ return (+ <Form+ validateOnBlur+ id="signIn-form"+ initialValues={{ email: '' }}+ validationSchema={signInSchema}+ onSubmit={onSignIn}+ >+ {({ isSubmitting }: { isSubmitting: boolean }) => {+ return (+ <div className="flex flex-col gap-4">+ <Input+ id="email"+ name="email"+ type="email"+ label="Email"+ placeholder="[email protected]"+ disabled={isSubmitting}+ />++ <div className="self-center">+ <HCaptcha+ ref={captchaRef}+ sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}+ size="invisible"+ onVerify={(token) => {+ setCaptchaToken(token)+ }}+ onExpire={() => {+ setCaptchaToken(null)+ }}+ />+ </div>++ <Button+ block+ form="signIn-form"+ htmlType="submit"+ size="large"+ disabled={isSubmitting}+ loading={isSubmitting}+ >+ Sign In+ </Button>+ </div>+ )+ }}+ </Form>+ )+}++export default SignInSSOFormdiff --git a/studio/components/interfaces/SignIn/SignInWithSSO.tsx b/studio/components/interfaces/SignIn/SignInWithSSO.tsxnew file mode 100644index 00000000000..c81ce30af43--- /dev/null+++ b/studio/components/interfaces/SignIn/SignInWithSSO.tsx@@ -0,0 +1,14 @@+import Link from 'next/link'+import { Button } from 'ui'++const SignInWithSSO = () => {+ return (+ <Link href="/sign-in-sso">+ <Button block size="small" type="text">+ Continue with SSO+ </Button>+ </Link>+ )+}++export default SignInWithSSOdiff --git a/studio/package.json b/studio/package.jsonindex 587ba186cfe..80597c5488e 100644--- a/studio/package.json+++ b/studio/package.json@@ -28,7 +28,7 @@"@supabase/postgres-meta": "^0.26.1","@supabase/react-data-grid": "^7.1.0-beta.7","@supabase/shared-types": "^0.1.29",- "@supabase/supabase-js": "^2.0.0",+ "@supabase/supabase-js": "^2.1.0","ajv": "^8.6.3","analytics-node": "^3.5.0","awesome-debounce-promise": "^2.1.0",diff --git a/studio/pages/sign-in-sso.tsx b/studio/pages/sign-in-sso.tsxnew file mode 100644index 00000000000..93047ad0105--- /dev/null+++ b/studio/pages/sign-in-sso.tsx@@ -0,0 +1,37 @@+import SignInSSOForm from 'components/interfaces/SignIn/SignInSSOForm'+import { SignInLayout } from 'components/layouts'+import Link from 'next/link'+import { NextPageWithLayout } from 'types'++const SignInSSOPage: NextPageWithLayout = () => {+ return (+ <>+ <div className="flex flex-col gap-5">+ <SignInSSOForm />+ </div>++ <div className="my-8 self-center text-sm">+ <div>+ <span className="text-scale-1000">Don't have an enterprise account?</span>{' '}+ <Link href="/sign-up">+ <a className="underline text-scale-1200 hover:text-scale-1100 transition">+ Sign Up Now+ </a>+ </Link>+ </div>+ </div>+ </>+ )+}++SignInSSOPage.getLayout = (page) => (+ <SignInLayout+ heading="Welcome back"+ subheading="Sign in to your enterprise account"+ logoLinkToMarketingSite={true}+ >+ {page}+ </SignInLayout>+)++export default SignInSSOPagediff --git a/studio/pages/sign-in.tsx b/studio/pages/sign-in.tsxindex a1ef0ac8163..d3b3b19b5ce 100644--- a/studio/pages/sign-in.tsx+++ b/studio/pages/sign-in.tsx@@ -9,6 +9,7 @@ const SignInPage: NextPageWithLayout = () => {<><div className="flex flex-col gap-5"><SignInWithGitHub />+ {/* <SignInWithSSO /> */}<div className="relative"><div className="absolute inset-0 flex items-center">