Skip to content

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

adds hcaptcha

Alaister Youngfd462cf054ae
diff --git a/package-lock.json b/package-lock.json
index 7ce25b0635c..985005c9b2e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3564,6 +3564,18 @@
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
}
},
+ "node_modules/@hcaptcha/react-hcaptcha": {
+ "version": "1.4.4",
+ "resolved": "https://registry.npmjs.org/@hcaptcha/react-hcaptcha/-/react-hcaptcha-1.4.4.tgz",
+ "integrity": "sha512-Aen217LDnf5ywbPSwBG5CsoqBLIHIAS9lhj3zQjXJuO13doQ6/ubkCWNuY8jmwYLefoFt3V3MrZmCdKDaFoTuQ==",
+ "dependencies": {
+ "@babel/runtime": "^7.17.9"
+ },
+ "peerDependencies": {
+ "react": ">= 16.3.0",
+ "react-dom": ">= 16.3.0"
+ }
+ },
"node_modules/@headlessui/react": {
"version": "1.7.3",
"resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.3.tgz",
@@ -36514,6 +36526,7 @@
"studio": {
"version": "0.0.9",
"dependencies": {
+ "@hcaptcha/react-hcaptcha": "^1.4.4",
"@headlessui/react": "^1.4.1",
"@monaco-editor/react": "^4.3.1",
"@next/bundle-analyzer": "^12.0.4",
@@ -38987,6 +39000,14 @@
"integrity": "sha512-NQ17ii0rK1b34VZonlmT2QMJFI70m0TRwbknO/ihlbatXyaktDhN/98vBiUU6kNBPljqGqyIrl2T4nY2RpFANg==",
"requires": {}
},
+ "@hcaptcha/react-hcaptcha": {
+ "version": "1.4.4",
+ "resolved": "https://registry.npmjs.org/@hcaptcha/react-hcaptcha/-/react-hcaptcha-1.4.4.tgz",
+ "integrity": "sha512-Aen217LDnf5ywbPSwBG5CsoqBLIHIAS9lhj3zQjXJuO13doQ6/ubkCWNuY8jmwYLefoFt3V3MrZmCdKDaFoTuQ==",
+ "requires": {
+ "@babel/runtime": "^7.17.9"
+ }
+ },
"@headlessui/react": {
"version": "1.7.3",
"resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.3.tgz",
@@ -61018,6 +61039,7 @@
"version": "file:studio",
"requires": {
"@babel/core": "^7.17.5",
+ "@hcaptcha/react-hcaptcha": "*",
"@headlessui/react": "^1.4.1",
"@monaco-editor/react": "^4.3.1",
"@next/bundle-analyzer": "^12.0.4",
@@ -61828,7 +61850,7 @@
"react-markdown": "^8.0.3",
"react-syntax-highlighter": "^15.3.1",
"remark": "^14.0.2",
- "remark-admonitions": "*",
+ "remark-admonitions": "^1.2.1",
"remark-html": "^15.0.0",
"remark-mdx": "^2.0.0-rc.2",
"remark-prism": "^1.3.6",
diff --git a/studio/components/interfaces/SignIn/ForgotPasswordForm.tsx b/studio/components/interfaces/SignIn/ForgotPasswordForm.tsx
index 32f6515687a..dfdfd52b0ff 100644
--- a/studio/components/interfaces/SignIn/ForgotPasswordForm.tsx
+++ b/studio/components/interfaces/SignIn/ForgotPasswordForm.tsx
@@ -1,7 +1,9 @@
+import HCaptcha from '@hcaptcha/react-hcaptcha'
import { useStore } from 'hooks'
import { post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { useRouter } from 'next/router'
+import { useRef, useState } from 'react'
import { Button, Form, Input } from 'ui'
import { object, string } from 'yup'
@@ -13,13 +15,25 @@ const ForgotPasswordForm = () => {
const { ui } = useStore()
const router = useRouter()
+ const [captchaToken, setCaptchaToken] = useState<string | null>(null)
+ const captchaRef = useRef<HCaptcha>(null)
+
const onForgotPassword = async ({ email }: { email: string }) => {
const toastId = ui.setNotification({
category: 'loading',
message: `Sending password reset email...`,
})
- const response = await post(`${API_URL}/reset-password`, { email })
+ let token = captchaToken
+ if (!token) {
+ const captchaResponse = await captchaRef.current?.execute({ async: true })
+ token = captchaResponse?.response ?? null
+ }
+
+ const response = await post(`${API_URL}/reset-password`, {
+ email,
+ captchaToken: token ?? undefined,
+ })
const error = response.error
if (!error) {
@@ -31,6 +45,8 @@ const ForgotPasswordForm = () => {
await router.push('/sign-in')
} else {
+ captchaRef.current?.resetCaptcha()
+
ui.setNotification({
id: toastId,
category: 'error',
@@ -49,7 +65,7 @@ const ForgotPasswordForm = () => {
>
{({ isSubmitting }: { isSubmitting: boolean }) => {
return (
- <div className="space-y-4 pt-4">
+ <div className="flex flex-col space-y-4 pt-4">
<Input
id="email"
name="email"
@@ -58,6 +74,20 @@ const ForgotPasswordForm = () => {
placeholder="[email protected]"
/>
+ <div className="self-center">
+ <HCaptcha
+ ref={captchaRef}
+ sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
+ size="invisible"
+ onVerify={(token) => {
+ setCaptchaToken(token)
+ }}
+ onExpire={() => {
+ setCaptchaToken(null)
+ }}
+ />
+ </div>
+
<div className="border-overlay-border border-t" />
<Button
diff --git a/studio/components/interfaces/SignIn/SignInForm.tsx b/studio/components/interfaces/SignIn/SignInForm.tsx
index 5d5dc753ff3..950c8757221 100644
--- a/studio/components/interfaces/SignIn/SignInForm.tsx
+++ b/studio/components/interfaces/SignIn/SignInForm.tsx
@@ -1,8 +1,10 @@
+import HCaptcha from '@hcaptcha/react-hcaptcha'
import { useStore } from 'hooks'
import { useParams } from 'hooks/misc/useParams'
import { auth } from 'lib/gotrue'
import Link from 'next/link'
import { useRouter } from 'next/router'
+import { useRef, useState } from 'react'
import { useSWRConfig } from 'swr'
import { Button, Form, Input } from 'ui'
import { object, string } from 'yup'
@@ -18,13 +20,26 @@ const SignInForm = () => {
const { returnTo } = useParams()
const { cache } = useSWRConfig()
+ const [captchaToken, setCaptchaToken] = useState<string | null>(null)
+ const captchaRef = useRef<HCaptcha>(null)
+
const onSignIn = async ({ email, password }: { email: string; password: string }) => {
const toastId = ui.setNotification({
category: 'loading',
message: `Logging in...`,
})
- const { error } = await auth.signInWithPassword({ email, password })
+ let token = captchaToken
+ if (!token) {
+ const captchaResponse = await captchaRef.current?.execute({ async: true })
+ token = captchaResponse?.response ?? null
+ }
+
+ const { error } = await auth.signInWithPassword({
+ email,
+ password,
+ options: { captchaToken: token ?? undefined },
+ })
if (!error) {
ui.setNotification({
@@ -39,6 +54,8 @@ const SignInForm = () => {
await router.push(returnTo ?? '/projects')
} else {
+ captchaRef.current?.resetCaptcha()
+
ui.setNotification({
id: toastId,
category: 'error',
@@ -81,6 +98,20 @@ const SignInForm = () => {
</Link>
</div>
+ <div className="self-center">
+ <HCaptcha
+ ref={captchaRef}
+ sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
+ size="invisible"
+ onVerify={(token) => {
+ setCaptchaToken(token)
+ }}
+ onExpire={() => {
+ setCaptchaToken(null)
+ }}
+ />
+ </div>
+
<Button
block
form="signIn-form"
diff --git a/studio/components/interfaces/SignIn/SignUpForm.tsx b/studio/components/interfaces/SignIn/SignUpForm.tsx
index 7c1a9f04d6a..83fd8cdf5bf 100644
--- a/studio/components/interfaces/SignIn/SignUpForm.tsx
+++ b/studio/components/interfaces/SignIn/SignUpForm.tsx
@@ -1,7 +1,9 @@
+import HCaptcha from '@hcaptcha/react-hcaptcha'
import { useStore } from 'hooks'
import { post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { useRouter } from 'next/router'
+import { useRef, useState } from 'react'
import { Button, Form, Input } from 'ui'
import { object, string } from 'yup'
@@ -16,13 +18,26 @@ const SignUpForm = () => {
const { ui } = useStore()
const router = useRouter()
+ const [captchaToken, setCaptchaToken] = useState<string | null>(null)
+ const captchaRef = useRef<HCaptcha>(null)
+
const onSignUp = async ({ email, password }: { email: string; password: string }) => {
const toastId = ui.setNotification({
category: 'loading',
message: `Signing up...`,
})
- const response = await post(`${API_URL}/signup`, { email, password })
+ let token = captchaToken
+ if (!token) {
+ const captchaResponse = await captchaRef.current?.execute({ async: true })
+ token = captchaResponse?.response ?? null
+ }
+
+ const response = await post(`${API_URL}/signup`, {
+ email,
+ password,
+ captchaToken: token ?? null,
+ })
const error = response.error
if (!error) {
@@ -34,6 +49,8 @@ const SignUpForm = () => {
await router.push('/sign-in')
} else {
+ captchaRef.current?.resetCaptcha()
+
ui.setNotification({
id: toastId,
category: 'error',
@@ -69,6 +86,20 @@ const SignUpForm = () => {
placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;"
/>
+ <div className="self-center">
+ <HCaptcha
+ ref={captchaRef}
+ sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
+ size="invisible"
+ onVerify={(token) => {
+ setCaptchaToken(token)
+ }}
+ onExpire={() => {
+ setCaptchaToken(null)
+ }}
+ />
+ </div>
+
<Button
block
form="signUp-form"
diff --git a/studio/package.json b/studio/package.json
index de7e56d817d..2b27b9535a5 100644
--- a/studio/package.json
+++ b/studio/package.json
@@ -14,6 +14,7 @@
"prettier:write": "prettier --write ."
},
"dependencies": {
+ "@hcaptcha/react-hcaptcha": "^1.4.4",
"@headlessui/react": "^1.4.1",
"@monaco-editor/react": "^4.3.1",
"@next/bundle-analyzer": "^12.0.4",