RlsSection.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { UseFormReturn } from 'react-hook-form'
  2. import { Badge, FormControl, FormField, SheetSection, Switch } from 'ui'
  3. import { Admonition } from 'ui-patterns'
  4. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  5. import { CreateQueueForm } from './CreateQueueSheet.schema'
  6. import { Markdown } from '@/components/interfaces/Markdown'
  7. export function RlsSection({
  8. form,
  9. isExposed,
  10. projectRef,
  11. }: {
  12. form: UseFormReturn<CreateQueueForm>
  13. isExposed: boolean | undefined
  14. projectRef: string | undefined
  15. }) {
  16. return (
  17. <SheetSection className="flex flex-col gap-y-2">
  18. <FormField
  19. control={form.control}
  20. name="enableRls"
  21. render={({ field }) => (
  22. <FormItemLayout
  23. layout="flex"
  24. label={
  25. <div className="flex items-center gap-x-2">
  26. <p>Enable Row Level Security (RLS)</p>
  27. <Badge variant="success">Recommended</Badge>
  28. </div>
  29. }
  30. description="Restrict access to your queue by enabling RLS and writing Postgres policies to control access for each role."
  31. >
  32. <FormControl>
  33. <Switch
  34. checked={field.value}
  35. onCheckedChange={field.onChange}
  36. disabled={field.disabled || isExposed}
  37. />
  38. </FormControl>
  39. </FormItemLayout>
  40. )}
  41. />
  42. {!isExposed ? (
  43. <Admonition
  44. type="default"
  45. title="Row Level Security for queues is only relevant if exposure through PostgREST has been enabled"
  46. >
  47. <Markdown
  48. className="[&>p]:leading-normal!"
  49. content={`You may opt to manage your queues via any Briven client libraries or PostgREST
  50. endpoints by enabling this in the [queues settings](/project/${projectRef}/integrations/queues/settings).`}
  51. />
  52. </Admonition>
  53. ) : (
  54. <Admonition
  55. type="default"
  56. title="RLS must be enabled as queues are exposed via PostgREST"
  57. description="This is to prevent anonymous access to any of your queues"
  58. />
  59. )}
  60. </SheetSection>
  61. )
  62. }