Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit c518c39

Browse files
committed
fix(recaptcha): fix recaptcha when registering with ctftime
1 parent 57e3a38 commit c518c39

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

client/src/components/ctftime-additional.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Form from '../components/form'
2+
import useRecaptcha from '../components/recaptcha'
23
import config from '../config'
34
import withStyles from '../components/jss'
45
import { register } from '../api/auth'
@@ -28,28 +29,28 @@ export default withStyles({
2829
const handleNameChange = useCallback(e => setName(e.target.value), [])
2930

3031
const [errors, setErrors] = useState({})
32+
const requestRecaptchaCode = useRecaptcha('register')
3133

32-
const handleRegister = useCallback(() => {
34+
const handleRegister = useCallback(async () => {
3335
setDisabledButton(true)
3436

35-
register({
37+
const { errors } = await register({
3638
ctftimeToken,
3739
name: name || undefined,
38-
division
40+
division,
41+
recaptchaCode: await requestRecaptchaCode?.()
3942
})
40-
.then(({ errors }) => {
41-
setDisabledButton(false)
43+
setDisabledButton(false)
4244

43-
if (!errors) {
44-
return
45-
}
46-
if (errors.name) {
47-
setShowName(true)
48-
}
45+
if (!errors) {
46+
return
47+
}
48+
if (errors.name) {
49+
setShowName(true)
50+
}
4951

50-
setErrors(errors)
51-
})
52-
}, [ctftimeToken, name, division])
52+
setErrors(errors)
53+
}, [ctftimeToken, name, division, requestRecaptchaCode])
5354

5455
const handleSubmit = useCallback(e => {
5556
e.preventDefault()

server/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ app.register(helmet, {
4141
directives: {
4242
defaultSrc: ['\'none\''],
4343
styleSrc: ['\'unsafe-inline\'', '\'self\''],
44-
scriptSrc: ['\'self\'', 'https://www.google-analytics.com'],
44+
scriptSrc: ['\'self\'', 'https://www.google-analytics.com', 'https://www.google.com/recaptcha/', 'https://www.gstatic.com/recaptcha/'],
45+
frameSrc: ['https://www.google.com/recaptcha/'],
4546
connectSrc: ['\'self\'', 'https://www.google-analytics.com'],
4647
imgSrc: ['*', 'data:']
4748
}

0 commit comments

Comments
 (0)