@artur9010/turnstile
v1.2.1
Published
Simple and easy Cloudflare Turnstile integration with Nuxt.js
Downloads
3
Maintainers
Readme
Cloudflare Turnstile for Nuxt 2
Based on Nuxt reCaptcha module. Created for use at https://mclist.io
Setup
- Add
@artur9010/turnstile
dependency withyarn
ornpm
into your project - Add
@artur9010/turnstile
tomodules
section ofnuxt.config.js
- Configure it:
{
modules: [
[
'@artur9010/turnstile', {
siteKey: ""
}
],
]
}
Runtime config
// nuxt.config.js
export default {
publicRuntimeConfig: {
turnstile: {
/* reCAPTCHA options */
siteKey: process.env.TURNSTILE_SITE_KEY // for example
}
}
}
Usage
- Add
<turnstile>
component inside your form:
<form @submit.prevent="onSubmit">
<input autocomplete="true" placeholder="Email" type="email" v-model="email">
<input autocomplete="current-password" placeholder="Password" type="password" v-model="password">
<turnstile />
<button type="submit">Sign In</button>
</form>
- Call
getResponse
inside form submit handler to get turnstile token:
async onSubmit() {
try {
const token = await this.$recaptcha.getResponse()
console.log('Turnstile token:', token)
// send token to server alongside your form data
// at the end you need to reset recaptcha
await this.$turnstile.reset()
} catch (error) {
console.log('Login error:', error)
}
},
Server Side
Check https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
Development
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Start development server using
npm run dev
License
Originally created by mvrlin [email protected]