Files
Ivan Vasilov 9ac44f5985 feat: Add Third Party Auth settings (#27564)
* Add queries and mutations for third party auth.

* Show the ThirdPartyAuth form in the auth settings.

* Minor fixes to the mutations.

* Add a comment for TODO.

* Add all components for third party auth.

* Minor fixes.

* Update the firebase icons.

* Update the api-types.

* Fix the barrel file imports.

* Make the sheets more intuitive.

* Add a dialog for adding RLS policies for the firebase integration.

* Hide the 3rd party auth section behind a form.

* Fix a type error.

* Update the wording on the Add RLS policy dialog.

* Replace the sheets with dialogs.

* Add fixes for the comments on github.

* Minor fixes.

* Fix a type error.

* Make the delete integration awaitable.
2024-07-25 11:07:09 +02:00

42 lines
1.3 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import FlagContext from 'components/ui/Flag/FlagContext'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useContext } from 'react'
export function useFlag<T = boolean>(name: string) {
const store: any = useContext(FlagContext)
const isObjectEmpty = (objectName: Object) => {
return Object.keys(objectName).length === 0
}
if (!isObjectEmpty(store) && store[name] === undefined) {
console.error(`Flag key "${name}" does not exist in flagStore`)
return false
}
return store[name] as T
}
export const useIsOptedIntoProjectLevelPermissions = (slug: string) => {
const orgsOptedIn = useFlag('projectLevelPermissionsOptIn') as string | undefined
const canReadSubscriptions = useCheckPermissions(
PermissionAction.BILLING_READ,
'stripe.subscriptions'
)
const { data: subscription } = useOrgSubscriptionQuery(
{ orgSlug: slug },
{ enabled: canReadSubscriptions }
)
const isEnterprise = subscription?.plan.id === 'enterprise'
if (!isEnterprise) return false
if (typeof orgsOptedIn === 'string') {
const organizations = orgsOptedIn.split(',').map((x) => x.trim())
return organizations.includes(slug)
} else {
return false
}
}