Files
supabase/apps/studio/components/ui/AlertError.tsx
Terry Sutton fc7f7f105a fix(studio): use public support link on MFA sign-in error (#46382)
Fixes: 
https://x.com/acgfbr/status/2058995058167185731

The default `<AlertError>`appends a `<ContactSupportButton>` that opens
the support form. It requires an authenticated session and `projectRef`.
On the pre-auth MFA error, neither exists, so the button doesn't work.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Enhanced error messaging in multi-factor authentication sign-in with
improved navigation options, allowing users to quickly return to sign-in
or contact support directly from error states.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46382?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 12:28:20 -02:30

117 lines
2.9 KiB
TypeScript

import { SupportCategories } from '@supabase/shared-types/out/constants'
import { PropsWithChildren, useEffect, useRef } from 'react'
import { Button } from 'ui'
import { Admonition } from 'ui-patterns/admonition'
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
import { useTrack } from '@/lib/telemetry/track'
export interface AlertErrorProps {
projectRef?: string
subject?: string
description?: string
error?: { message: string } | null
layout?: 'vertical' | 'horizontal' | 'responsive'
className?: string
showIcon?: boolean
showInstructions?: boolean
showErrorPrefix?: boolean
additionalActions?: React.ReactNode
hideContactSupport?: boolean
}
export const ContactSupportButton = ({
projectRef,
subject,
error,
}: {
projectRef?: string
subject?: string
error?: { message: string } | null
}) => {
return (
<Button asChild type="default" className="w-min">
<SupportLink
queryParams={{
category: SupportCategories.DASHBOARD_BUG,
projectRef,
subject,
error: error?.message,
}}
>
Contact support
</SupportLink>
</Button>
)
}
// [Joshen] To standardize the language for all error UIs
export const AlertError = ({
projectRef,
subject,
description = 'Try refreshing your browser, but if the issue persists for more than a few minutes, please reach out to us via support.',
error,
className,
showIcon = true,
layout = 'responsive',
showInstructions = true,
showErrorPrefix = true,
children,
additionalActions,
hideContactSupport = false,
}: PropsWithChildren<AlertErrorProps>) => {
const track = useTrack()
const hasTrackedRef = useRef(false)
const formattedErrorMessage = error?.message?.includes('503')
? '503 Service Temporarily Unavailable'
: error?.message
useEffect(() => {
if (!hasTrackedRef.current) {
hasTrackedRef.current = true
if (Math.random() < 0.1) {
track('dashboard_error_created', {
source: 'admonition',
})
}
}
}, [track])
return (
<Admonition
type="warning"
layout={additionalActions ? 'vertical' : layout}
showIcon={showIcon}
title={subject}
description={
<>
{error?.message && (
<p>
{showErrorPrefix && 'Error: '}
{formattedErrorMessage}
</p>
)}
{showInstructions && <p>{description}</p>}
{children}
</>
}
actions={
hideContactSupport ? (
(additionalActions ?? null)
) : additionalActions ? (
<>
{additionalActions}
<ContactSupportButton projectRef={projectRef} subject={subject} error={error} />
</>
) : (
<ContactSupportButton projectRef={projectRef} subject={subject} error={error} />
)
}
className={className}
/>
)
}
export default AlertError