Files
supabase/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/AddRLSPolicyForFirebaseDialog.tsx
Ivan Vasilov fd3309c886 feat: UI for pg-cron (#29291)
* Add crons option in the database menu.

* Add react-hook-form to the studio package.json.

* Refactor the functionSelector to be used by other features.

* Add the bulk of the functionality for the cron UI. Some of the code is copy-pasted from functions feature, needs to be cleaned before merging.

* Tons of changes, the Create Cron sheet works now.

* Added some more functionality for the cronjob feature.

* Convert the Cron table to a listing with cards.

* Add click-to-copy in the Auth Hooks feature.

* Remove extra prop.

* Fix type errors.

* Fix some random issues. Fix the tests.

* Fix the tests.

* Add a style for disabled radio button item.

* Make the default SQL snippet. Handle the case pg_net is not installed.

* Fix the heading and save button when creating a new cron job.

* Change the name of the custom label in the schedule dropdown.

* Minor fixes.

* Rename all mentions of cronjobs to cron jobs.

* Always show the cron jobs link.

* Rename the link from crons to cron-jobs.

* Fix the disabled state for the stacked radio group.

* More minor fixes.

* More small fixes.

* Fix the tests.

* Minor UI tweaks

* More minor tweaks

* Add padding bottom

* Add feature flag for the cron ui.

* Fix the SQL function option.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-10-03 15:11:17 -02:30

83 lines
2.3 KiB
TypeScript

import { copyToClipboard } from 'lib/helpers'
import { Check } from 'lucide-react'
import Link from 'next/link'
import { useEffect, useState } from 'react'
import {
Button,
DialogDescription,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
} from 'ui'
import { SQLCodeBlock } from './SqlCodeBlock'
export const AddRLSPolicyForFirebaseDialog = ({
projectRef,
firebaseProjectId,
}: {
projectRef: string
firebaseProjectId: string
}) => {
const description = `create policy
"Restrict access to Firebase Auth for project ID ${firebaseProjectId}"
on table_name
as restrictive
to authenticated using (
(
auth.jwt()->>'iss' = 'https://${projectRef}.supabase.co/auth/v1'
)
or (
auth.jwt()->>'iss' = 'https://securetoken.google.com/${firebaseProjectId}'
and auth.jwt()->>'aud' = '${firebaseProjectId}'
)
);`
const [copied, setCopied] = useState(false)
useEffect(() => {
if (!copied) return
const timer = setTimeout(() => setCopied(false), 2000)
return () => clearTimeout(timer)
}, [copied])
function handleCopy(formatted: string) {
copyToClipboard(formatted, () => setCopied(true))
}
return (
<>
<DialogHeader padding={'small'}>
<DialogTitle>Add RLS policy</DialogTitle>
<DialogDescription>
We recommend adding a Row Level Security (RLS) policy for your Firebase JWT keys to
explicitly specify which tables can be accessed via the Data APIs in order to prevent
accidental exposure of data.
</DialogDescription>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection padding={'small'}>
<SQLCodeBlock>{[description]}</SQLCodeBlock>
</DialogSection>
<DialogFooter padding={'small'}>
<Button
type="default"
onClick={() => handleCopy(description)}
icon={copied ? <Check className="text-brand-600" /> : null}
>
{copied ? <p>Copied</p> : <p>Copy code</p>}
</Button>
<Button type="primary">
<Link
href={`/project/${projectRef}/sql/new?content=${encodeURIComponent(description)}`}
passHref
>
Open in SQL Editor
</Link>
</Button>
</DialogFooter>
</>
)
}