Skip to content

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

feat: add mfa enforcement toggle (#34307)

Etienne Stalmans6d09404779ac
diff --git a/apps/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsx b/apps/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsx
index ab4c993426d..a7a76ce15dc 100644
--- a/apps/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsx
+++ b/apps/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsx
@@ -1,13 +1,17 @@
+import { useQueryClient } from '@tanstack/react-query'
import { Dispatch, SetStateAction, useEffect, useState } from 'react'
import { toast } from 'sonner'
-import { Input } from 'ui'
-import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
+import { LOCAL_STORAGE_KEYS } from 'common'
import InformationBox from 'components/ui/InformationBox'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { organizationKeys } from 'data/organizations/keys'
import { useMfaChallengeAndVerifyMutation } from 'data/profile/mfa-challenge-and-verify-mutation'
import { useMfaEnrollMutation } from 'data/profile/mfa-enroll-mutation'
import { useMfaUnenrollMutation } from 'data/profile/mfa-unenroll-mutation'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
+import { Input } from 'ui'
+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
interface AddNewFactorModalProps {
visible: boolean
@@ -43,7 +47,6 @@ const AddNewFactorModal = ({ visible, onClose }: AddNewFactorModalProps) => {
factorName={name}
factor={data as Extract<typeof data, { type: 'totp' }>}
isLoading={isEnrolling}
- onSuccess={() => onClose()}
onClose={onClose}
/>
</>
@@ -100,7 +103,6 @@ interface SecondStepProps {
}
}
isLoading: boolean
- onSuccess: () => void
onClose: () => void
}
@@ -109,19 +111,27 @@ const SecondStep = ({
factorName,
factor: outerFactor,
isLoading,
- onSuccess,
onClose,
}: SecondStepProps) => {
const [code, setCode] = useState('')
+ const queryClient = useQueryClient()
+
+ const [lastVisitedOrganization] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION,
+ ''
+ )
const { mutate: unenroll } = useMfaUnenrollMutation({ onSuccess: () => onClose() })
const { mutate: challengeAndVerify, isLoading: isVerifying } = useMfaChallengeAndVerifyMutation({
onError: (error) => {
toast.error(`Failed to add a second factor authentication: ${error?.message}`)
},
- onSuccess: () => {
+ onSuccess: async () => {
+ if (lastVisitedOrganization) {
+ await queryClient.invalidateQueries(organizationKeys.members(lastVisitedOrganization))
+ }
toast.success(`Successfully added a second factor authentication`)
- onSuccess()
+ onClose()
},
})
@@ -160,51 +170,49 @@ const SecondStep = ({
}}
onConfirm={() => factor && challengeAndVerify({ factorId: factor.id, code })}
>
- <>
- <div className="py-4 pb-0 text-sm">
- <span>
- Use an authenticator app to scan the following QR code, and provide the code from the
- app to complete the enrolment.
- </span>
+ <div className="py-4 pb-0 text-sm">
+ <span>
+ Use an authenticator app to scan the following QR code, and provide the code from the app
+ to complete the enrolment.
+ </span>
+ </div>
+ {isLoading && (
+ <div className="pb-4 px-4">
+ <GenericSkeletonLoader />
</div>
- {isLoading && (
- <div className="pb-4 px-4">
- <GenericSkeletonLoader />
- </div>
- )}
- {factor && (
- <>
- <div className="flex justify-center py-6">
- <div className="h-48 w-48 bg-white rounded">
- <img width={190} height={190} src={factor.totp.qr_code} alt={factor.totp.uri} />
- </div>
- </div>
- <div>
- <InformationBox
- title="Unable to scan?"
- description={
- <Input
- copy
- disabled
- id="ref"
- size="small"
- label="You can also enter this secret key into your authenticator app"
- value={factor.totp.secret}
- />
- }
- />
- </div>
- <div className="pt-2 pb-4">
- <Input
- label="Authentication code"
- value={code}
- placeholder="XXXXXX"
- onChange={(e) => setCode(e.target.value)}
- />
+ )}
+ {factor && (
+ <>
+ <div className="flex justify-center py-6">
+ <div className="h-48 w-48 bg-white rounded">
+ <img width={190} height={190} src={factor.totp.qr_code} alt={factor.totp.uri} />
</div>
- </>
- )}
- </>
+ </div>
+ <div>
+ <InformationBox
+ title="Unable to scan?"
+ description={
+ <Input
+ copy
+ disabled
+ id="ref"
+ size="small"
+ label="You can also enter this secret key into your authenticator app"
+ value={factor.totp.secret}
+ />
+ }
+ />
+ </div>
+ <div className="pt-2 pb-4">
+ <Input
+ label="Authentication code"
+ value={code}
+ placeholder="XXXXXX"
+ onChange={(e) => setCode(e.target.value)}
+ />
+ </div>
+ </>
+ )}
</ConfirmationModal>
)
}
diff --git a/apps/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx b/apps/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx
index 6b6d3a0a322..d72b59a3711 100644
--- a/apps/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx
+++ b/apps/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx
@@ -1,6 +1,10 @@
+import { useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
+import { LOCAL_STORAGE_KEYS } from 'common'
+import { organizationKeys } from 'data/organizations/keys'
import { useMfaUnenrollMutation } from 'data/profile/mfa-unenroll-mutation'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
interface DeleteFactorModalProps {
@@ -16,8 +20,17 @@ const DeleteFactorModal = ({
lastFactorToBeDeleted,
onClose,
}: DeleteFactorModalProps) => {
+ const queryClient = useQueryClient()
+ const [lastVisitedOrganization] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION,
+ ''
+ )
+
const { mutate: unenroll, isLoading } = useMfaUnenrollMutation({
- onSuccess: () => {
+ onSuccess: async () => {
+ if (lastVisitedOrganization) {
+ await queryClient.invalidateQueries(organizationKeys.members(lastVisitedOrganization))
+ }
toast.success(`Successfully deleted factor`)
onClose()
},
@@ -49,6 +62,9 @@ const DeleteFactorModal = ({
<>
<li>Adding another authenticator app as a factor prior to deleting</li>
<li>Ensure that your account does not need multi-factor authentication</li>
+ <li>
+ You will lose access to any organization that enforces multi-factor authentication
+ </li>
</>
) : (
<>
diff --git a/apps/studio/components/interfaces/Organization/SecuritySettings/SecuritySettings.tsx b/apps/studio/components/interfaces/Organization/SecuritySettings/SecuritySettings.tsx
new file mode 100644
index 00000000000..906fb82dc4e
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/SecuritySettings/SecuritySettings.tsx
@@ -0,0 +1,223 @@
+import { zodResolver } from '@hookform/resolvers/zod'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
+import Link from 'next/link'
+import { useEffect } from 'react'
+import { useForm } from 'react-hook-form'
+import { toast } from 'sonner'
+import { z } from 'zod'
+
+import { useParams } from 'common'
+import { ScaffoldContainerLegacy } from 'components/layouts/Scaffold'
+import AlertError from 'components/ui/AlertError'
+import { InlineLink } from 'components/ui/InlineLink'
+import NoPermission from 'components/ui/NoPermission'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { useOrganizationMembersQuery } from 'data/organizations/organization-members-query'
+import { useOrganizationMfaToggleMutation } from 'data/organizations/organization-mfa-mutation'
+import { useOrganizationMfaQuery } from 'data/organizations/organization-mfa-query'
+import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
+import { useProfile } from 'lib/profile'
+import {
+ Alert_Shadcn_,
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Button,
+ Card,
+ CardContent,
+ CardFooter,
+ Form_Shadcn_,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Switch,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ WarningIcon,
+} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+
+const schema = z.object({
+ enforceMfa: z.boolean(),
+})
+
+const SecuritySettings = () => {
+ const { slug } = useParams()
+ const { profile } = useProfile()
+ const selectedOrganization = useSelectedOrganization()
+ const { data: members } = useOrganizationMembersQuery({ slug })
+ const canReadMfaConfig = useCheckPermissions(PermissionAction.READ, 'organizations')
+ const canUpdateMfaConfig = useCheckPermissions(PermissionAction.UPDATE, 'organizations')
+
+ const isPaidPlan = selectedOrganization?.plan.id !== 'free'
+
+ const {
+ data: mfaConfig,
+ error: mfaError,
+ isLoading: isLoadingMfa,
+ isError: isErrorMfa,
+ isSuccess: isSuccessMfa,
+ } = useOrganizationMfaQuery({ slug }, { enabled: canReadMfaConfig })
+
+ const { mutate: toggleMfa, isLoading: isUpdatingMfa } = useOrganizationMfaToggleMutation({
+ onError: (error) => {
+ toast.error(`Failed to update MFA enforcement: ${error.message}`)
+ if (mfaConfig !== undefined) form.reset({ enforceMfa: mfaConfig })
+ },
+ onSuccess: (data) => {
+ toast.success('Successfully updated organization MFA settings')
+ },
+ })
+
+ const form = useForm<z.infer<typeof schema>>({
+ resolver: zodResolver(schema),
+ defaultValues: {
+ enforceMfa: false,
+ },
+ })
+
+ useEffect(() => {
+ if (mfaConfig !== undefined) {
+ form.reset({ enforceMfa: mfaConfig })
+ }
+ }, [mfaConfig, form])
+
+ const hasMFAEnabled =
+ members?.find((member) => member.primary_email == profile?.primary_email)?.mfa_enabled || false
+
+ const onSubmit = (values: { enforceMfa: boolean }) => {
+ if (!slug || !isPaidPlan) return
+ toggleMfa({ slug, setEnforced: values.enforceMfa })
+ }
+
+ if (!canReadMfaConfig) {
+ return (
+ <ScaffoldContainerLegacy>
+ <NoPermission resourceText="view organization security settings" />
+ </ScaffoldContainerLegacy>
+ )
+ }
+
+ return (
+ <ScaffoldContainerLegacy>
+ {!isPaidPlan && (
+ <Alert_Shadcn_
+ variant="default"
+ title="Organization MFA enforcement is not available on Free plan"
+ >
+ <WarningIcon />
+ <div className="flex flex-col md:flex-row pt-1 gap-4">
+ <div className="grow">
+ <AlertTitle_Shadcn_>
+ Organization MFA enforcement is not available on Free plan
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_ className="flex flex-row justify-between gap-3">
+ <p>Upgrade to Pro or above to enforce MFA requirements for your organization.</p>
+ </AlertDescription_Shadcn_>
+ </div>
+
+ <div className="flex items-center">
+ <Button type="primary" asChild>
+ <Link href={`/org/${slug}/billing?panel=subscriptionPlan&source=mfa`}>
+ Upgrade subscription
+ </Link>
+ </Button>
+ </div>
+ </div>
+ </Alert_Shadcn_>
+ )}
+
+ {(isErrorMfa || mfaError) && isPaidPlan && (
+ <AlertError error={mfaError} subject="Failed to retrieve MFA enforcement status" />
+ )}
+
+ {isLoadingMfa && (
+ <Card>
+ <CardContent>
+ <GenericSkeletonLoader />
+ </CardContent>
+ </Card>
+ )}
+
+ {isSuccessMfa && isPaidPlan && (
+ <Form_Shadcn_ {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)}>
+ <Card>
+ <CardContent>
+ <FormField_Shadcn_
+ control={form.control}
+ name="enforceMfa"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Require MFA to access organization"
+ description="Team members must have MFA enabled and a valid MFA session to access the organization and any projects."
+ >
+ <FormControl_Shadcn_>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <div>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ disabled={
+ !isPaidPlan ||
+ !canUpdateMfaConfig ||
+ !hasMFAEnabled ||
+ isUpdatingMfa
+ }
+ />
+ </div>
+ </TooltipTrigger>
+ {(!canUpdateMfaConfig || !hasMFAEnabled) && (
+ <TooltipContent side="bottom">
+ {!canUpdateMfaConfig ? (
+ "You don't have permission to update MFA settings"
+ ) : (
+ <>
+ <InlineLink href="/account/security">Enable MFA</InlineLink> on
+ your own account first
+ </>
+ )}
+ </TooltipContent>
+ )}
+ </Tooltip>
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+ <CardFooter className="justify-end space-x-2">
+ {form.formState.isDirty && (
+ <Button
+ type="default"
+ disabled={isLoadingMfa || isUpdatingMfa}
+ onClick={() => form.reset({ enforceMfa: isPaidPlan ? mfaConfig : false })}
+ >
+ Cancel
+ </Button>
+ )}
+ <Button
+ type="primary"
+ htmlType="submit"
+ disabled={
+ !isPaidPlan ||
+ !canUpdateMfaConfig ||
+ isUpdatingMfa ||
+ isLoadingMfa ||
+ !form.formState.isDirty
+ }
+ loading={isUpdatingMfa}
+ >
+ Save changes
+ </Button>
+ </CardFooter>
+ </Card>
+ </form>
+ </Form_Shadcn_>
+ )}
+ </ScaffoldContainerLegacy>
+ )
+}
+
+export default SecuritySettings
diff --git a/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx b/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
index ce93229c347..b4572404993 100644
--- a/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
+++ b/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx
@@ -100,6 +100,7 @@ const TeamSettings = () => {
<>
<ScaffoldContainerLegacy>
{newLayoutPreview && <ScaffoldTitle>Team</ScaffoldTitle>}
+
<ScaffoldFilterAndContent>
<ScaffoldActionsContainer className="w-full flex-col md:flex-row gap-2 justify-between">
<Input
diff --git a/apps/studio/components/interfaces/Organization/index.ts b/apps/studio/components/interfaces/Organization/index.ts
index a48f73b8f58..d107edbefe7 100644
--- a/apps/studio/components/interfaces/Organization/index.ts
+++ b/apps/studio/components/interfaces/Organization/index.ts
@@ -1,5 +1,6 @@
export { default as BillingSettings } from './BillingSettings/BillingSettings'
export { default as GeneralSettings } from './GeneralSettings/GeneralSettings'
+export { default as SecuritySettings } from './SecuritySettings/SecuritySettings'
export { default as IntegrationSettings } from './IntegrationSettings/IntegrationSettings'
export { default as InvoicesSettings } from './InvoicesSettings/InvoicesSettings'
export { default as NewOrgForm } from './NewOrg/NewOrgForm'
diff --git a/apps/studio/components/interfaces/Sidebar.tsx b/apps/studio/components/interfaces/Sidebar.tsx
index 3a03f2d54b2..2dfe419886b 100644
--- a/apps/studio/components/interfaces/Sidebar.tsx
+++ b/apps/studio/components/interfaces/Sidebar.tsx
@@ -501,7 +501,8 @@ const OrganizationLinks = () => {
? router.pathname.includes('/general') ||
router.pathname.includes('/apps') ||
router.pathname.includes('/audit') ||
- router.pathname.includes('/documents')
+ router.pathname.includes('/documents') ||
+ router.pathname.includes('/security')
: activeRoute === item.key
}
route={{
diff --git a/apps/studio/components/layouts/ProjectLayout/OrganizationSettingsLayout.tsx b/apps/studio/components/layouts/ProjectLayout/OrganizationSettingsLayout.tsx
index 3f2f0ba4006..3f3a28c6734 100644
--- a/apps/studio/components/layouts/ProjectLayout/OrganizationSettingsLayout.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/OrganizationSettingsLayout.tsx
@@ -4,15 +4,20 @@ import { PropsWithChildren } from 'react'
import { useParams } from 'common'
import { useIsNewLayoutEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { useCurrentPath } from 'hooks/misc/useCurrentPath'
+import { useFlag } from 'hooks/ui/useFlag'
import { NavMenu, NavMenuItem } from 'ui'
import { ScaffoldContainerLegacy, ScaffoldTitle } from '../Scaffold'
function OrganizationSettingsLayout({ children }: PropsWithChildren) {
+ const { slug } = useParams()
+
const newLayoutPreview = useIsNewLayoutEnabled()
- const { slug } = useParams()
- const fullCurrentPath = useCurrentPath()
+ // [Joshen] RE Organization Settings - need to figure out how to enforce MFA across users before this goes live
+ const newSecurityPage = useFlag('showOrganizationSecuritySettings')
+
// Get the path without any hash values
+ const fullCurrentPath = useCurrentPath()
const [currentPath] = fullCurrentPath.split('#')
// hide these settings in the new layout
@@ -39,6 +44,10 @@ function OrganizationSettingsLayout({ children }: PropsWithChildren) {
label: 'General',
href: `/org/${slug}/general`,
},
+ newSecurityPage && {
+ label: 'Security',
+ href: `/org/${slug}/security`,
+ },
!newLayoutPreview && {
label: 'Team',
href: `/org/${slug}/team`,
diff --git a/apps/studio/data/organizations/keys.ts b/apps/studio/data/organizations/keys.ts
index fb74eee4f15..97b6940e4d6 100644
--- a/apps/studio/data/organizations/keys.ts
+++ b/apps/studio/data/organizations/keys.ts
@@ -2,6 +2,7 @@ export const organizationKeys = {
list: () => ['organizations'] as const,
detail: (slug?: string) => ['organizations', slug] as const,
members: (slug?: string) => ['organizations', slug, 'members'] as const,
+ mfa: (slug?: string) => ['organizations', slug, 'mfa'] as const,
paymentMethods: (slug: string | undefined) => ['organizations', slug, 'payment-methods'] as const,
roles: (slug: string | undefined) => ['organizations', slug, 'roles'] as const,
freeProjectLimitCheck: (slug: string | undefined) =>
diff --git a/apps/studio/data/organizations/organization-mfa-mutation.ts b/apps/studio/data/organizations/organization-mfa-mutation.ts
new file mode 100644
index 00000000000..483d804d639
--- /dev/null
+++ b/apps/studio/data/organizations/organization-mfa-mutation.ts
@@ -0,0 +1,57 @@
+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
+import { toast } from 'sonner'
+
+import { patch, handleError } from 'data/fetchers'
+import type { ResponseError } from 'types'
+import { organizationKeys } from './keys'
+
+export type OrganizationMfaToggleVariables = {
+ slug: string
+ setEnforced: boolean
+}
+
+export async function toggleOrganizationMfa({ slug, setEnforced }: OrganizationMfaToggleVariables) {
+ if (!slug) {
+ throw new Error('Slug is required')
+ }
+ const { data, error } = await patch('/platform/organizations/{slug}/members/mfa/enforcement', {
+ params: { path: { slug } },
+ body: { enforced: setEnforced },
+ })
+ if (error) handleError(error)
+ return data
+}
+
+type OrganizationMfaToggleData = Awaited<ReturnType<typeof toggleOrganizationMfa>>
+
+export const useOrganizationMfaToggleMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<
+ UseMutationOptions<OrganizationMfaToggleData, ResponseError, OrganizationMfaToggleVariables>,
+ 'mutationFn'
+> = {}) => {
+ const queryClient = useQueryClient()
+
+ return useMutation<OrganizationMfaToggleData, ResponseError, OrganizationMfaToggleVariables>(
+ (vars) => toggleOrganizationMfa(vars),
+ {
+ async onSuccess(data, variables, context) {
+ const { slug } = variables
+
+ // We already have the data, no need to refetch
+ queryClient.setQueryData(organizationKeys.mfa(slug), data.enforced)
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to update MFA enforcement: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ }
+ )
+}
diff --git a/apps/studio/data/organizations/organization-mfa-query.ts b/apps/studio/data/organizations/organization-mfa-query.ts
new file mode 100644
index 00000000000..fc608a431c8
--- /dev/null
+++ b/apps/studio/data/organizations/organization-mfa-query.ts
@@ -0,0 +1,41 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+import { get, handleError } from 'data/fetchers'
+import type { ResponseError } from 'types'
+import { organizationKeys } from './keys'
+
+export type OrganizationMfaVariables = {
+ slug?: string
+}
+
+export async function getOrganizationMfaEnforcement(
+ { slug }: OrganizationMfaVariables,
+ signal?: AbortSignal
+) {
+ if (!slug) throw new Error('slug is required')
+
+ const orgMfa = await get('/platform/organizations/{slug}/members/mfa/enforcement', {
+ params: { path: { slug } },
+ signal,
+ })
+
+ const { data: orgMfaRequired, error: orgMfaError } = orgMfa
+
+ if (orgMfaError) handleError(orgMfaError)
+
+ return orgMfaRequired?.enforced
+}
+
+export type OrganizationMfaError = ResponseError
+
+export const useOrganizationMfaQuery = <TData = boolean>(
+ { slug }: OrganizationMfaVariables,
+ { enabled = true, ...options }: UseQueryOptions<boolean, OrganizationMfaError, TData> = {}
+) =>
+ useQuery<boolean, OrganizationMfaError, TData>(
+ organizationKeys.mfa(slug),
+ ({ signal }) => getOrganizationMfaEnforcement({ slug }, signal),
+ {
+ enabled: enabled && typeof slug !== 'undefined',
+ ...options,
+ }
+ )
diff --git a/apps/studio/pages/org/[slug]/security.tsx b/apps/studio/pages/org/[slug]/security.tsx
new file mode 100644
index 00000000000..b2f4af6ba6e
--- /dev/null
+++ b/apps/studio/pages/org/[slug]/security.tsx
@@ -0,0 +1,33 @@
+import { SecuritySettings } from 'components/interfaces/Organization'
+import AppLayout from 'components/layouts/AppLayout/AppLayout'
+import DefaultLayout from 'components/layouts/DefaultLayout'
+import OrganizationLayout from 'components/layouts/OrganizationLayout'
+import OrganizationSettingsLayout from 'components/layouts/ProjectLayout/OrganizationSettingsLayout'
+import { Loading } from 'components/ui/Loading'
+import { usePermissionsQuery } from 'data/permissions/permissions-query'
+import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
+import type { NextPageWithLayout } from 'types'
+
+const OrgGeneralSettings: NextPageWithLayout = () => {
+ const { isLoading: isLoadingPermissions } = usePermissionsQuery()
+ const selectedOrganization = useSelectedOrganization()
+
+ return (
+ <>
+ {selectedOrganization === undefined && isLoadingPermissions ? (
+ <Loading />
+ ) : (
+ <SecuritySettings />
+ )}
+ </>
+ )
+}
+
+OrgGeneralSettings.getLayout = (page) => (
+ <DefaultLayout>
+ <OrganizationLayout>
+ <OrganizationSettingsLayout>{page}</OrganizationSettingsLayout>
+ </OrganizationLayout>
+ </DefaultLayout>
+)
+export default OrgGeneralSettings
diff --git a/apps/studio/state/app-state.ts b/apps/studio/state/app-state.ts
index 22012f85f9f..f95a0dcfaf0 100644
--- a/apps/studio/state/app-state.ts
+++ b/apps/studio/state/app-state.ts
@@ -121,6 +121,19 @@ export const appState = proxy({
appState.docsLanguage = value
},
+ isOptedInTelemetry: false,
+ setIsOptedInTelemetry: (value: boolean | null) => {
+ appState.isOptedInTelemetry = value === null ? false : value
+ if (typeof window !== 'undefined' && value !== null) {
+ localStorage.setItem(COMMON_LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT, value.toString())
+ }
+ },
+
+ isMfaEnforced: false,
+ setIsMfaEnforced: (value: boolean) => {
+ appState.isMfaEnforced = value
+ },
+
showEnableBranchingModal: false,
setShowEnableBranchingModal: (value: boolean) => {
appState.showEnableBranchingModal = value
diff --git a/packages/ui-patterns/Dialogs/ConfirmationModal.tsx b/packages/ui-patterns/Dialogs/ConfirmationModal.tsx
index 71d0230e87c..ff22a5d2f4d 100644
--- a/packages/ui-patterns/Dialogs/ConfirmationModal.tsx
+++ b/packages/ui-patterns/Dialogs/ConfirmationModal.tsx
@@ -46,7 +46,7 @@ const ConfirmationModal = forwardRef<
visible,
onCancel,
onConfirm,
- loading: loading_ = false,
+ loading: loading_,
cancelLabel = 'Cancel',
confirmLabel = 'Submit',
confirmLabelLoading,
@@ -58,21 +58,27 @@ const ConfirmationModal = forwardRef<
},
ref
) => {
- useEffect(() => {
- if (visible) {
- setLoading(false)
- }
- }, [visible])
-
- const [loading, setLoading] = useState(false)
+ // [Joshen] If `loading_` is provided, let loading state be entirely controlled by the param
+ // Otherwise, if the action onConfirm errors out, the UI is stuck in a loading state
+ const [loading, setLoading] = useState(loading_ !== undefined ? loading_ : false)
const onSubmit: MouseEventHandler<HTMLButtonElement> = (e) => {
e.preventDefault()
e.stopPropagation()
- setLoading(true)
onConfirm()
+ if (loading === undefined) setLoading(true)
}
+ useEffect(() => {
+ if (visible && loading_ === undefined) {
+ setLoading(false)
+ }
+ }, [visible])
+
+ useEffect(() => {
+ if (loading_ !== undefined) setLoading(loading_)
+ }, [loading_])
+
return (
<Dialog
open={visible}