npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@delaneydev/laravel-turnstile-vue

v1.0.4

Published

A Vue 3 component wrapper for Cloudflare Turnstile, designed for use with Laravel apps.

Readme

Laravel Turnstile Vue

A reusable, SSR-safe Cloudflare Turnstile CAPTCHA component for Vue 3 — made to pair seamlessly with Laravel via njoguamos/laravel-turnstile.

NPM
GitHub


✨ Features

  • SSR-safe with hydration checks
  • 🔁 Auto-reset on error/expired (optional)
  • 🔒 v-model for reactive token binding
  • 🧩 Exposes reset() and execute() methods
  • 🧠 Designed to work with Laravel (Inertia, Blade, Livewire)
  • ⚙️ Server-side validation handled via njoguamos/laravel-turnstile

📦 Installation (Frontend)

npm install @delaneydev/laravel-turnstile-vue

⚙️ Laravel Backend Setup

This component is designed to work alongside:

njoguamos/laravel-turnstile

1. Install the Laravel Turnstile package

composer require njoguamos/laravel-turnstile

2. Publish the config

php artisan turnstile:install

3. Add your Turnstile credentials to .env

TURNSTILE_SITE_KEY=your-site-key
TURNSTILE_SECRET_KEY=your-secret-key
TURNSTILE_ENABLED=true
# Use TURNSTILE_ENABLED=false to disable in testing/dev

4. Share the Site Key with Inertia

Update your HandleInertiaRequests.php middleware:

public function share(Request $request): array
{
    return array_merge(parent::share($request), [
        'turnstile_site_key' => env('TURNSTILE_SITE_KEY'),
    ]);
}

🔐 Jetstream Integration (with Turnstile Middleware)

To apply Cloudflare Turnstile validation to Jetstream login and password routes, override the default auth routes importing the Jetstream controllers directly from vendor (do not create new ones) in routes/web.php.

// Override Jetstream login routes to include 'turnstile' middleware
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\NewPasswordController;

Route::post('/login', [AuthenticatedSessionController::class, 'store'])
    ->middleware(['guest', 'turnstile'])
    ->name('login');

Route::post('/forgot-password', [PasswordResetLinkController::class, 'store'])
    ->middleware(['guest', 'turnstile'])
    ->name('password.email');

Route::post('/reset-password', [NewPasswordController::class, 'store'])
    ->middleware(['guest', 'turnstile'])
    ->name('password.update');

For a full explanation of why this override is needed, this way we dont break jetstream or need to maintain our own auth controllers direct from vendor read this article:
Integrating Cloudflare Turnstile CAPTCHA with Laravel Jetstream by Delaney Wright


✅ Server-Side Validation

Option A — Using a Form Request

use NjoguAmos\Turnstile\Rules\TurnstileRule;

class RegisterRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'token' => ['required', new TurnstileRule()],
        ];
    }
}

Option B — Inline in a Controller

use NjoguAmos\Turnstile\Rules\TurnstileRule;

public function store(Request $request)
{
    $validated = $request->validate([
        'token' => ['required', new TurnstileRule()],
    ]);
}

💻 Frontend Usage

Inertia Example

<script setup lang="ts">
import { TurnstileWidget } from '@delaneydev/laravel-turnstile-vue'
const captchaToken = ref('')
</script>

<template>
  <TurnstileWidget
    v-model="captchaToken"
    :sitekey="$page.props.turnstile_site_key"
    theme="light"
  />
</template>

Jetstream Login Example

<script setup lang="ts">
import { useForm, usePage } from '@inertiajs/vue3'
import { ref, watch } from 'vue'

const captchaToken = ref('')
const form = useForm({
  email: '',
  password: '',
  remember: false,
})

const submit = () => {
  form
    .transform(data => ({
      ...data,
      'cf-turnstile-response': captchaToken.value,
      remember: form.remember ? 'on' : '',
    }))
    .post(route('login'), {
      onFinish: () => {
        form.reset('password')
        captchaToken.value = ''
      },
      onError: () => {
        captchaToken.value = ''
      },
    })
}
</script>

<template>
  <form @submit.prevent="submit">
    <!-- Email, password, remember fields -->
    <TurnstileWidget
      v-model="captchaToken"
      :sitekey="$page.props.turnstile_site_key"
      theme="dark"
    />
    <button type="submit">Log in</button>
  </form>
</template>

🔐 Props

| Prop | Type | Default | Description | |--------------------|-----------|-----------|-------------| | sitekey | string | — | Your Cloudflare Turnstile site key (required) | | modelValue | string | — | Bound CAPTCHA token via v-model | | theme | string | 'light' | light or dark | | size | string | 'normal'| normal, compact, or invisible | | disableAutoReload| boolean | false | Prevents auto-reset on error/expired |


🎯 Events

| Event | Payload | Description | |--------------------|-----------|--------------------------------------| | update:modelValue| string | Token emitted after success | | error | — | Widget failed to load | | expired | — | Widget expired (auto-reset if enabled) |


🔧 Methods

<script setup>
const captcha = ref()
</script>

<template>
  <TurnstileWidget ref="captcha" sitekey="..." v-model="token" />
  <button @click="captcha?.execute()">Force Execute</button>
</template>

🧠 SSR Support

✅ Out-of-the-box SSR safe.

  • Uses v-if="hydrated" to defer rendering until client
  • Checks typeof window !== 'undefined' to prevent SSR DOM issues
  • Compatible with:
    • Nuxt 3
    • Laravel SSR (Inertia)
    • Vite SSR
    • Vue CLI/Nitro setups

🧪 Usage Outside Laravel

You can use this in any Vue 3 project:

<TurnstileWidget
  sitekey="your-site-key"
  v-model="captchaToken"
/>

Just handle the token validation via your own backend logic or API if you're not using Laravel.


🔖 License

MIT © DelaneyDev