Skip to content

reCAPTCHA 🔐

Overview

reCAPTCHA is a security service by Google that protects websites from spam, abuse, and malicious activities by differentiating between humans and bots. JetShip comes with reCAPTCHA support built-in, making it easier for you to safeguard your site from unwanted activities like:

  • Scraping
  • Brute-force attacks
  • Automated abuse (spam form submissions, etc.)

This documentation will guide you through setting up and managing reCAPTCHA in JetShip.

Setting Up reCAPTCHA 🛠️

To get started with reCAPTCHA, follow these steps:

  1. Visit the reCAPTCHA Admin Console.
  2. Register your site by filling out the form:
    • Label: Give your site a name that helps you identify it.
    • reCAPTCHA Type: Select "Challenge (v2)" for the most commonly used version.
    • Domain: Add your domain. If you are working locally, enter localhost for development purposes.
  3. Once registered, you will receive two important keys:
    • Site Key 🔑
    • Secret Key 🔐
  4. In your JetShip admin panel, navigate to Settings > General Settings > reCAPTCHA and enter these keys.

Enabling/Disabling reCAPTCHA ✅❌

You can easily enable or disable reCAPTCHA through the JetShip admin panel. Here's how:

  1. Go to Settings > General Settings in the admin panel.
  2. Navigate to the reCAPTCHA section
  3. Use the toggle switch to enable or disable reCAPTCHA.
  4. Ensure you’ve entered the Site Key and Secret Key you obtained earlier in the form.

Once enabled, reCAPTCHA will automatically appear on your login and registration pages to protect against automated abuse.

🗒️ Note

Currently, reCAPTCHA is only integrated on the login and registration forms. However, you can easily extend this to other forms on your site, such as waitlists, newsletters, contact forms, etc., as needed.

How to Add reCAPTCHA to Other Pages 📄

JetShip uses the laravel-recaptcha package to implement reCAPTCHA. To add it to other pages, you can follow the instructions in the laravel-recaptcha documentation.

Additionally, you can refer to the login and registration page code for examples, where reCAPTCHA is already integrated. Below is a quick code snippet from the login page to help you implement reCAPTCHA in your Blade templates.

Example Code Snippet: Adding reCAPTCHA in Blade

php
@if (config('app.recaptcha_enabled'))
  <div class="my-4">
    {!! htmlFormSnippet() !!}
  </div>
  @error('g-recaptcha-response')
    <span class="text-xs text-red-500" role="alert">
      {{ $message }}
    </span>
  @enderror
  @push('head')
    {!! htmlScriptTagJsApi() !!}
  @endpush
@endif

Explanation

  • htmlFormSnippet(): This method renders the reCAPTCHA widget in your Blade template.
  • htmlScriptTagJsApi(): This includes the necessary reCAPTCHA script in your page’s <head>, so the widget can load properly.
  • Error Handling: If the reCAPTCHA validation fails, the error message is displayed below the form in red text.