Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
@nuxtjs/recaptcha
Advanced tools
Readme
🤖 Simple and easy Google reCAPTCHA integration with Nuxt.js
@nuxtjs/recaptcha
dependency with yarn
or npm
into your project@nuxtjs/recaptcha
to modules
section of nuxt.config.js
{
modules: [
[
'@nuxtjs/recaptcha', {
/* reCAPTCHA options */
}
],
]
}
using top level options
{
modules: [
'@nuxtjs/recaptcha',
],
recaptcha: {
/* reCAPTCHA options */
},
}
{
// ...
recaptcha: {
hideBadge: Boolean, // Hide badge element (v3 & v2 via size=invisible)
language: String, // Recaptcha language (v2)
mode: String, // Mode: 'base', 'enterprise'
siteKey: String, // Site key for requests
version: Number, // Version
size: String // Size: 'compact', 'normal', 'invisible' (v2)
},
// ...
}
// nuxt.config.js
export default {
publicRuntimeConfig: {
recaptcha: {
/* reCAPTCHA options */
siteKey: process.env.RECAPTCHA_SITE_KEY // for example
}
}
}
You can generate keys for the basic
mode by registering a new site.
For the enterprise
mode, use the Google Cloud Console.
<recaptcha>
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">
<recaptcha />
<button type="submit">Sign In</button>
</form>
getResponse
inside form submit handler to get reCAPTCHA token:async onSubmit() {
try {
const token = await this.$recaptcha.getResponse()
console.log('ReCaptcha token:', token)
// send token to server alongside your form data
// at the end you need to reset recaptcha
await this.$recaptcha.reset()
} catch (error) {
console.log('Login error:', error)
}
},
See:
init
function inside mounted
hook of your pageasync mounted() {
try {
await this.$recaptcha.init()
} catch (e) {
console.error(e);
}
}
execute
function form submit handler to get reCAPTCHA token:async onSubmit() {
try {
const token = await this.$recaptcha.execute('login')
console.log('ReCaptcha token:', token)
// send token to server alongside your form data
} catch (error) {
console.log('Login error:', error)
}
}
destroy
function inside beforeDestroy
hook of the page. (This will remove reCAPTCHA scripts, styles and badge from the page)beforeDestroy() {
this.$recaptcha.destroy()
}
See:
When you send data + token
to the server, you should verify the token on the server side to make sure it does not requested from a bot.
You can find out how to verify token on the server side by looking at the server middleware inside v2 example. (The server side is same for both versions)
You're allowed to hide the badge (i.e. for v3 and v2 invisible), as long as you include the recaptcha branding in the user flow.
For example:
<small>This site is protected by reCAPTCHA and the Google
<a href="https://policies.google.com/privacy">Privacy Policy</a> and
<a href="https://policies.google.com/terms">Terms of Service</a> apply.
</small>
yarn install
or npm install
npm run dev
Copyright (c) mvrlin mvrlin@pm.me
FAQs
Simple and easy Google reCAPTCHA integration with Nuxt.js
The npm package @nuxtjs/recaptcha receives a total of 19,464 weekly downloads. As such, @nuxtjs/recaptcha popularity was classified as popular.
We found that @nuxtjs/recaptcha demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.