Files
supabase/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/AddRLSPolicyForFirebaseDialog.tsx
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

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 projectRef={projectRef!}>{[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>
</>
)
}