Skip to content

Commit

Permalink
try fix captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
ug.rp committed Apr 27, 2024
1 parent 8e5b45e commit c56cf0e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
REACT_APP_SUPABASE_URL=https://oupgudlkspsmzkmeovlh.supabase.co
REACT_APP_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im91cGd1ZGxrc3BzbXprbWVvdmxoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTM0NTIwNzQsImV4cCI6MjAyOTAyODA3NH0.KAbKFBChJHtxTmOZM2pdeppIyNbcnQkEgSi6RA7OQdo

# hcaptcha
REACT_APP_HCAPTCHA_SITE_KEY="b0a493f2-49df-486b-bdee-b8459f7b1c21"


# radi4000 api
REACT_APP_RADIO4000_API_URL=https://api.radio4000.com
Expand Down
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@hcaptcha/react-hcaptcha": "^1.10.1",
"@supabase/supabase-js": "^1.35.6",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
Expand Down
24 changes: 19 additions & 5 deletions src/components/auth-form.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {useState} from 'react'
import {useNavigate} from 'react-router-dom'
import HCaptcha from "@hcaptcha/react-hcaptcha"
import config from 'config'


export default function Auth({onSubmit, submitLabel, redirectTo}) {
const navigate = useNavigate()
const [loading, setLoading] = useState(false)
const [message, setMessage] = useState(false)
const [errorMessage, setErrorMessage] = useState(false)
const [data, setData] = useState({email: '', password: ''})
const {email, password} = data
const [data, setData] = useState({email: '', password: '', token: ''})

const handleChange = ({target}) => {
const {name, value} = target
Expand All @@ -16,6 +18,12 @@ export default function Auth({onSubmit, submitLabel, redirectTo}) {
[name]: value,
})
}
const handleVerificationSuccess = (newToken) => {
setData({
...data,
token: newToken
})
}

const handleSubmit = (e) => {
e.preventDefault()
Expand All @@ -32,7 +40,7 @@ export default function Auth({onSubmit, submitLabel, redirectTo}) {
} else {
setErrorMessage(false)
}
if (!password) {
if (!data.password) {
setMessage('Check your email for the login link!')
} else if (redirectTo) {
navigate(redirectTo, {replace: true})
Expand All @@ -53,7 +61,7 @@ export default function Auth({onSubmit, submitLabel, redirectTo}) {
type="email"
placeholder="Your email"
autoFocus={true}
value={email}
value={data.email}
disabled={loading}
onChange={handleChange}
required
Expand All @@ -64,11 +72,17 @@ export default function Auth({onSubmit, submitLabel, redirectTo}) {
name="password"
type="password"
placeholder="Your password"
value={password}
value={data.password}
disabled={loading}
onChange={handleChange}
/>
</label>
<label>Captcha
<HCaptcha
sitekey={config.HCAPTCHA_SITE_KEY}
onVerify={handleVerificationSuccess}
/>
</label>
<button disabled={loading} type="submit">
{loading ? <span>Loading</span> : <span>{submitLabel || 'Send magic link'}</span>}
</button>
Expand Down
8 changes: 5 additions & 3 deletions src/components/db-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ export default function DbSession({children}) {
userChannel,
setUserChannel /* usisng the state setter to set active channel as userChannel */,
signOut: () => database.auth.signOut(),
signIn: ({email, password}) => {
signIn: ({email, password, token}) => {
const options = {captchaToken: token}
if (password) {
return database.auth.signIn({email, password})
debugger
return database.auth.signIn({email, password, options})
} else {
return database.auth.signIn({email})
return database.auth.signIn({email, options})
}
},
signUp: async ({email, password}) => {
Expand Down
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config = {
/* if having the r4-api deployed */
RADIO4000_API_URL: process.env.REACT_APP_RADIO4000_API_URL|| 'https://api.radio4000.com',

/* Hcpatch */
HCAPTCHA_SITE_KEY: process.env.REACT_APP_HCAPTCHA_SITE_KEY,

/* if connecting to supabase db/auth */
SUPABASE_URL: process.env.REACT_APP_SUPABASE_URL,
SUPABASE_ANON_KEY: process.env.REACT_APP_SUPABASE_ANON_KEY,
Expand Down

0 comments on commit c56cf0e

Please sign in to comment.