# vue-recaptcha-v3

> [![npm](https://img.shields.io/npm/v/vue-recaptcha-v3.svg)](https://www.npmjs.com/package/vue-recaptcha-v3) [![npm type definitions](https://img.shields.io/npm/types/vue-recaptcha-v3.svg)](https://www.npmjs.com/package/vue-recaptcha-v3)

Latest version **2.0.1** (published 2021-04-13) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install vue-recaptcha-v3
pnpm add vue-recaptcha-v3
yarn add vue-recaptcha-v3
bun add vue-recaptcha-v3
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-04-13 |
| First published | 2018-11-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 249 |
| Author | AurityLab |
| Maintainers | wipeair |
| Keywords | captcha, recaptcha, recaptcha-v3, vue, vuejs |

## Links

- npm: https://www.npmjs.com/package/vue-recaptcha-v3
- Repository: https://github.com/AurityLab/vue-recaptcha-v3
- Issues: https://github.com/AurityLab/vue-recaptcha-v3/issues
- npm.io page: https://npm.io/package/vue-recaptcha-v3

## Dependencies (1)

- [recaptcha-v3](https://npm.io/package/recaptcha-v3.md) ^1.8.0

## Recent versions

- 2.0.1 (latest) — 2021-04-13
- 2.0.0 — 2020-11-08
- 1.9.0 — 2020-04-02
- 1.8.0 — 2019-12-04
- 1.7.2 — 2019-11-30
- 1.7.0 — 2019-09-30
- 1.6.1 — 2019-09-28
- 1.5.0 — 2019-04-28
- 1.4.0 — 2019-02-24
- 1.3.1 — 2019-02-21
- 1.3.0 — 2019-02-20
- 1.2.1 — 2018-12-30
- 1.2.0 — 2018-12-28
- 1.1.1 — 2018-11-15
- 1.0.1 — 2018-11-14
- … 1 more at https://npm.io/package/vue-recaptcha-v3/versions

## README

# Vue reCAPTCHA-v3
[![npm](https://img.shields.io/npm/v/vue-recaptcha-v3.svg)](https://www.npmjs.com/package/vue-recaptcha-v3)
[![npm type definitions](https://img.shields.io/npm/types/vue-recaptcha-v3.svg)](https://www.npmjs.com/package/vue-recaptcha-v3)

A simple and easy to use reCAPTCHA (v3 only) library for Vue based on [reCAPTCHA-v3](https://github.com/AurityLab/recaptcha-v3).

**The latest version of this package supports Vue 3!** [See here for Vue 2 usage](https://github.com/AurityLab/vue-recaptcha-v3/tree/vue-v2.x). 

## Install
With NPM:
```bash
$ npm install vue-recaptcha-v3
```

With Yarn:
```bash
$ yarn add vue-recaptcha-v3
```
 
## Prerequisites
To use this package you only need a valid site key for your domain, which you can easily get [here](https://www.google.com/recaptcha).

## Usage

```javascript
import Vue from 'vue'
import { VueReCaptcha } from 'vue-recaptcha-v3'

// For more options see below
Vue.use(VueReCaptcha, { siteKey: '<site key>' })

new Vue({
  methods: {
    async recaptcha() {
      // (optional) Wait until recaptcha has been loaded.
      await this.$recaptchaLoaded()

      // Execute reCAPTCHA with action "login".
      const token = await this.$recaptcha('login')

      // Do stuff with the received token.
    }
  },
  template: '<button @click="recaptcha">Execute recaptcha</button>'
})
```

### Vue 3 Composition

```js
import { createApp } from 'vue'
import { VueReCaptcha, useReCaptcha } from 'vue-recaptcha-v3'

const component = {
  setup() {
    const { executeRecaptcha, recaptchaLoaded } = useReCaptcha()

    const recaptcha = async () => {
      // (optional) Wait until recaptcha has been loaded.
      await recaptchaLoaded()

      // Execute reCAPTCHA with action "login".
      const token = await executeRecaptcha('login')

      // Do stuff with the received token.
    }

    return {
      recaptcha
    }
  },
  template: '<button @click="recaptcha">Execute recaptcha</button>'
}

createApp(component)
  .use(VueReCaptcha, { siteKey: '<site key>' })
```

### TypeScript + Vue 3
To get type suggestions for instance variables (this is not needed for composition API), create a new file called `shims-vue-recaptcha-v3.d.ts` and put the following inside it:
```ts
import { ReCaptchaInstance } from 'recaptcha-v3'

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $recaptcha: (action: string) => Promise<string>
    $recaptchaLoaded: () => Promise<boolean>
    $recaptchaInstance: ReCaptchaInstance
  }
}
```

## Options
This plugin offers optional options to configure the behavior of some parts.

Available options:

|Name|Description|Type|Default value
|----|-----------|----|-------------
|siteKey|The site key for your domain from Google.|*string*|*none*
|loaderOptions|Optional options for the [recaptcha-v3](https://github.com/AurityLab/recaptcha-v3) loader. The available options are described [here](https://github.com/AurityLab/recaptcha-v3/#load-options-usage).|*object*|`null`

### Usage
To use the options just pass an object to the `Vue.use(...)` method. For example:
```javascript
import Vue from 'vue'
import { VueReCaptcha } from 'vue-recaptcha-v3'

Vue.use(VueReCaptcha, {
  siteKey: '<site key>',
  loaderOptions: {
    useRecaptchaNet: true
  }
})
```

## Advanced usage
Some topics which are not commonly used, but required in some cases.

### Access [reCAPTCHA-v3](https://github.com/AurityLab/recaptcha-v3/#load-options-usage) instance
In some cases it's necessary to interact with the reCAPTCHA-v3 instance, which provides more control over reCAPTCHA. 
```javascript
const recaptcha = this.$recaptchaInstance

// Hide reCAPTCHA badge:
recaptcha.hideBadge()

// Show reCAPTCHA badge:
recaptcha.showBadge()
```

---
_Source: https://npm.io/package/vue-recaptcha-v3 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
