mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-04-26 10:04:25 -05:00
feat: configurable and optional hCaptcha sitekey
This commit is contained in:
parent
f6ac4332f9
commit
106370836f
|
|
@ -24,7 +24,11 @@ export default defineNuxtConfig({
|
||||||
},
|
},
|
||||||
|
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
apiBase: 'https://api.pretendo.cc'
|
apiBase: 'https://api.pretendo.cc',
|
||||||
|
|
||||||
|
public: {
|
||||||
|
hCaptchaSitekey: ''
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
css: ['~/assets/css/main.css'],
|
css: ['~/assets/css/main.css'],
|
||||||
|
|
|
||||||
|
|
@ -12,35 +12,33 @@ const errorMessage = ref<string | null>();
|
||||||
const invisibleHcaptcha = ref<VueHcaptcha | null>(null);
|
const invisibleHcaptcha = ref<VueHcaptcha | null>(null);
|
||||||
|
|
||||||
async function registerSubmission() {
|
async function registerSubmission() {
|
||||||
if (invisibleHcaptcha.value) {
|
try {
|
||||||
try {
|
const hCaptchaResponse = invisibleHcaptcha.value ? (await invisibleHcaptcha.value.executeAsync()).response : null;
|
||||||
const hCaptchaResponse = (await invisibleHcaptcha.value.executeAsync()).response;
|
|
||||||
|
|
||||||
await $fetch('/api/account/register', {
|
await $fetch('/api/account/register', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { ...registerForm, hCaptchaResponse }
|
body: { ...registerForm, hCaptchaResponse }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof redirect.value === 'string') {
|
if (typeof redirect.value === 'string') {
|
||||||
await navigateTo(redirect.value);
|
await navigateTo(redirect.value);
|
||||||
} else {
|
} else {
|
||||||
await navigateTo('/account');
|
await navigateTo('/account');
|
||||||
}
|
|
||||||
} catch (error: unknown) {
|
|
||||||
if (error instanceof FetchError) {
|
|
||||||
errorMessage.value = error.statusText;
|
|
||||||
} else {
|
|
||||||
if (error === 'challenge-closed') { // Thrown if the captcha is closed, can be safely ignored
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorMessage.value = `Error during registration: ${error}`; // TODO: localize
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(() => { // TODO: replace this toast
|
|
||||||
errorMessage.value = null;
|
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof FetchError) {
|
||||||
|
errorMessage.value = error.statusText;
|
||||||
|
} else {
|
||||||
|
if (error === 'challenge-closed') { // Thrown if the captcha is closed, can be safely ignored
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorMessage.value = `Error during registration: ${error}`; // TODO: localize
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => { // TODO: replace this toast
|
||||||
|
errorMessage.value = null;
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -119,8 +117,9 @@ async function registerSubmission() {
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<vue-hcaptcha
|
<vue-hcaptcha
|
||||||
|
v-if="$config.public.hCaptchaSitekey"
|
||||||
ref="invisibleHcaptcha"
|
ref="invisibleHcaptcha"
|
||||||
sitekey="cf3fd74e-93ca-47e6-9fa0-5fc439de06d4"
|
:sitekey="$config.public.hCaptchaSitekey"
|
||||||
class="h-captcha"
|
class="h-captcha"
|
||||||
size="invisible"
|
size="invisible"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user