adonis-captcha
v0.0.3
Published
Captcha provider for adonisjs framework
Downloads
13
Maintainers
Readme
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