mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
Drops the remaining Next-era shims and aliases that only existed for the dual runtime (FE-3106). Part 14 of the stack. **Depends on:** #53222 **Changed:** - ~45 files – import Sentry from `@sentry/react` directly instead of the aliased `@sentry/nextjs` - `hooks/ui/usePreventNavigationOnUnsavedChanges.ts` – is now the TanStack `useBlocker` implementation (previously swapped in by a Vite alias) - `components/interfaces/App/RouteValidationWrapper.tsx` – `next/router` → `useNavigate` + the leaf route's `fullPath` (`/project/$ref/sql/$id`) for the exempt-route and last-visited checks - `hooks/misc/withAuth.tsx` – no `getLayout` forwarding - `TemplateEditor.test.tsx` – renders inside a router for the unsaved-changes blocker **Removed:** - `compat/sentry-nextjs.ts` and its Vite alias, the `usePreventNavigationOnUnsavedChanges` alias and Next hook, `types/next.ts` (`NextPageWithLayout`), the `@sentry/nextjs` dependency The `compat/next/*` shims for `link`, `router`, `head`, `image`, `navigation`, `dynamic` and `script` stay: about 300 components outside `routes/**` still import them. Addresses [FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages). ## To test - Trigger an error (e.g. a failing query) – it reaches Sentry as before - Edit an email template or edge function and navigate away – the unsaved-changes prompt appears - Open an org you don't belong to – toast and redirect home; open a SQL snippet, leave and come back – last snippet is restored --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
89 lines
2.9 KiB
TypeScript
89 lines
2.9 KiB
TypeScript
import * as Sentry from '@sentry/react'
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
|
import { getAccessToken } from 'common'
|
|
import { useEffect, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { LogoLoader } from 'ui'
|
|
|
|
import { SignInMfaForm } from '@/components/interfaces/SignIn/SignInMfaForm'
|
|
import { ForgotPasswordLayout } from '@/components/layouts/SignInLayout/ForgotPasswordLayout'
|
|
import { auth, buildPathWithParams, getReturnToPath } from '@/lib/gotrue'
|
|
|
|
export const Route = createFileRoute('/_auth/forgot-password-mfa')({
|
|
component: ForgotPasswordMfaPage,
|
|
})
|
|
|
|
function ForgotPasswordMfaPage() {
|
|
const navigate = useNavigate()
|
|
const queryClient = useQueryClient()
|
|
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
// This useEffect redirects the user to MFA if they're already halfway signed in
|
|
useEffect(() => {
|
|
auth
|
|
.initialize()
|
|
.then(async ({ error }) => {
|
|
if (error) {
|
|
// if there was a problem signing in via the url, don't redirect
|
|
setLoading(false)
|
|
return
|
|
}
|
|
|
|
const token = await getAccessToken()
|
|
|
|
if (token) {
|
|
const { data, error } = await auth.mfa.getAuthenticatorAssuranceLevel()
|
|
if (error) {
|
|
// if there was a problem signing in via the url, don't redirect
|
|
toast.error(
|
|
`Failed to retrieve assurance level: ${error.message}. Please try signing in again`
|
|
)
|
|
setLoading(false)
|
|
return navigate({ to: '/sign-in', search: true })
|
|
}
|
|
|
|
if (data.currentLevel === data.nextLevel) {
|
|
await queryClient.resetQueries()
|
|
void navigate({ href: getReturnToPath() })
|
|
return
|
|
} else {
|
|
// Show the MFA form
|
|
setLoading(false)
|
|
return
|
|
}
|
|
} else {
|
|
// if the user doesn't have a token, he needs to go back to the sign-in page
|
|
const redirectTo = buildPathWithParams('/sign-in')
|
|
void navigate({ href: redirectTo, replace: true })
|
|
return
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
Sentry.captureException(error)
|
|
console.error('Auth initialization error:', error)
|
|
toast.error('Failed to initialize authentication. Please try again.')
|
|
setLoading(false)
|
|
void navigate({ to: '/sign-in', search: true })
|
|
})
|
|
}, [])
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="flex flex-col flex-1 bg-alternative h-screen items-center justify-center">
|
|
<LogoLoader />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<ForgotPasswordLayout
|
|
heading="Complete two-factor authentication"
|
|
subheading="Enter the authentication code from your two-factor authentication app before changing your password"
|
|
>
|
|
<SignInMfaForm context="forgot-password" />
|
|
</ForgotPasswordLayout>
|
|
)
|
|
}
|