Skip to content

yariksav/adonis-captcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adonis Captcha Provider

This package helps you to use recaptcha in your project

Setup

Install the package from npm

adonis install adonis-captcha

Then register provider in start/app.js:

const providers = [
  ...
  'adonis-captcha/providers/CaptchaProvider'
]

Usage as middleware

Add row in start/kernel.js

const namedMiddleware = {
  ...
  recaptcha: 'Adonis/Middleware/Captcha',
}

Then in your route

  Route.post('account/register', 'AccountController.register').middleware(['recaptcha'])

Use in tests

const Captcha = use('Capptcha')

...

test('try to register new user', async ({ assert, client}) => {
  Captcha.fake()
  const user = await User.create(newUser)

  const response = await client.post('account/register')
    .send({
      username: 'test'
    })
    .end()

  response.assertStatus(200)

  Captcha.restore()
})

Use directly

const Captcha = use('Captcha')
await Captcha.validate(request.input('recaptcha-token'))

validate will throw Error when recaphca is incorrect

About

Recaptcha module for AdonisJS framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published