Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: adds verify support email page (#46331)

barcofourie85be44aab080
diff --git a/apps/studio/components/interfaces/SupportEmailVerification/SupportEmailVerification.tsx b/apps/studio/components/interfaces/SupportEmailVerification/SupportEmailVerification.tsx
new file mode 100644
index 00000000000..a069588c854
--- /dev/null
+++ b/apps/studio/components/interfaces/SupportEmailVerification/SupportEmailVerification.tsx
@@ -0,0 +1,80 @@
+import { useParams } from 'common'
+import { useEffect } from 'react'
+import { Admonition, ShimmeringLoader } from 'ui-patterns'
+
+import { InterstitialLayout, SupabaseLogo } from '@/components/layouts/InterstitialLayout'
+import { useVerifyEmailMutation } from '@/data/support/support-email-verification-mutation'
+
+export const SupportEmailVerification = () => {
+ const { token } = useParams()
+
+ const {
+ mutate: verifyEmail,
+ isPending,
+ isSuccess,
+ isError,
+ error,
+ } = useVerifyEmailMutation({ onError: () => {} })
+
+ useEffect(() => {
+ if (token) {
+ verifyEmail({ token })
+ }
+ }, [token, verifyEmail])
+
+ const isExpiredOrUsed = isError && error?.code === 410
+
+ const withLayout = (title: string, children: React.ReactNode) => (
+ <InterstitialLayout logo={<SupabaseLogo />} title={title}>
+ <div className="px-6 pb-6">{children}</div>
+ </InterstitialLayout>
+ )
+
+ if (!token) {
+ return withLayout(
+ 'Email Verification',
+ <Admonition
+ type="warning"
+ description="No verification token was found. Please use the link from your email."
+ />
+ )
+ }
+
+ if (isPending) {
+ return withLayout(
+ 'Verifying your email…',
+ <div className="flex flex-col gap-3">
+ <ShimmeringLoader className="h-4 w-full py-0" />
+ <ShimmeringLoader className="h-4 w-3/4 py-0" />
+ </div>
+ )
+ }
+
+ if (isSuccess) {
+ return withLayout(
+ 'Account linked',
+ <Admonition
+ type="success"
+ description="Thanks for verifying, our team now has the context they need to resolve your issue more efficiently. You can close this page."
+ />
+ )
+ }
+
+ if (isExpiredOrUsed) {
+ return withLayout(
+ 'Link no longer valid',
+ <Admonition
+ type="warning"
+ description="This verification link has already been used or has expired. You can close this page."
+ />
+ )
+ }
+
+ return withLayout(
+ 'Verification failed',
+ <Admonition
+ type="destructive"
+ description="We weren't able to verify your identity this time. Our team will still be in touch, verification just helps us view your organization and project details to resolve your issue more efficiently. You can close this page."
+ />
+ )
+}
diff --git a/apps/studio/data/support/support-email-verification-mutation.ts b/apps/studio/data/support/support-email-verification-mutation.ts
new file mode 100644
index 00000000000..ae6cba48822
--- /dev/null
+++ b/apps/studio/data/support/support-email-verification-mutation.ts
@@ -0,0 +1,57 @@
+import { useMutation } from '@tanstack/react-query'
+import { toast } from 'sonner'
+
+import { constructHeaders, fetchHandler, handleError } from '@/data/fetchers'
+import { API_URL } from '@/lib/constants'
+import type { ResponseError, UseCustomMutationOptions } from '@/types'
+
+export type VerifyEmailVariables = {
+ token: string
+}
+
+export type VerifyEmailData = {
+ result: 'success'
+}
+
+export async function verifyEmail({ token }: VerifyEmailVariables): Promise<VerifyEmailData> {
+ const baseUrl = API_URL?.replace('/platform', '')
+ const url = `${baseUrl}/platform/support/verify-email`
+ const headers = await constructHeaders({ 'Content-Type': 'application/json' })
+
+ const res = await fetchHandler(url, {
+ method: 'POST',
+ headers,
+ body: JSON.stringify({ token }),
+ })
+
+ if (!res.ok) {
+ const body = await res.json().catch(() => ({}))
+ handleError({ ...body, code: res.status })
+ }
+
+ return res.json() as Promise<VerifyEmailData>
+}
+
+export const useVerifyEmailMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<
+ UseCustomMutationOptions<VerifyEmailData, ResponseError, VerifyEmailVariables>,
+ 'mutationFn'
+> = {}) => {
+ return useMutation<VerifyEmailData, ResponseError, VerifyEmailVariables>({
+ mutationFn: (vars) => verifyEmail(vars),
+ async onSuccess(data, variables, context) {
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to verify email: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ })
+}
diff --git a/apps/studio/pages/verify-email.tsx b/apps/studio/pages/verify-email.tsx
new file mode 100644
index 00000000000..ccf286c93f7
--- /dev/null
+++ b/apps/studio/pages/verify-email.tsx
@@ -0,0 +1,20 @@
+import Head from 'next/head'
+
+import { SupportEmailVerification } from '@/components/interfaces/SupportEmailVerification/SupportEmailVerification'
+import { buildStudioPageTitle } from '@/lib/page-title'
+import type { NextPageWithLayout } from '@/types'
+
+const PAGE_TITLE = buildStudioPageTitle({ section: 'Email Verification', brand: 'Supabase' })
+
+const VerifyEmailPage: NextPageWithLayout = () => {
+ return (
+ <>
+ <Head>
+ <title>{PAGE_TITLE}</title>
+ </Head>
+ <SupportEmailVerification />
+ </>
+ )
+}
+
+export default VerifyEmailPage