Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error When Disabling on Local Environment #22

Open
JamesCobbledick opened this issue Dec 15, 2020 · 10 comments
Open

Error When Disabling on Local Environment #22

JamesCobbledick opened this issue Dec 15, 2020 · 10 comments

Comments

@JamesCobbledick
Copy link

Expected

Disable the use of honey on the local environment by commenting out config.honey.environments.local
Successfully submit a form, even though it has 'honey' & 'honey-recaptcha' middleware on the server side and <x-honey recaptcha="message"/> on the front end.

Actual Result

Error is thrown with the following: Typed property Lukeraymonddowning\Honey\Recaptcha::$response must not be accessed before initialization.

It then points to here: \vendor\lukeraymonddowning\honey\src\Recaptcha.php:60

@lukeraymonddowning
Copy link
Owner

Couple of checks if you don't mind:

  • What is your APP_ENV in your .env file?
  • What version of Honey are you using?

@JamesCobbledick
Copy link
Author

APP_ENV=local

I have honey in composer.json as 0.3.1

@JamesCobbledick
Copy link
Author

I've just found that this error is in the console if used on a page that's making use of Vue?

`app.js:331324 [Vue warn]: Error compiling template:

Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.`

Maybe my implementation is wrong?

@lukeraymonddowning
Copy link
Owner

Are you using it in Vue itself? Or is Vue just on the page somewhere?

@JamesCobbledick
Copy link
Author

It's in a blade file, that just has Vue on the page.

@lukeraymonddowning
Copy link
Owner

I'm really struggling to replicate this, in tests or otherwise. Any chance of snippets of your code?

@JamesCobbledick
Copy link
Author

JamesCobbledick commented Dec 18, 2020

The code is essentially this;

Blade file

<div id="app">
<form action="{{route('company.send.message')}}>
<x-honey recaptcha="message"/>
</form>
</div>

Web.php

Route::post('/send-message', [CompanyController::class, 'sendDirectMessage']) ->middleware('throttle:3,1') ->middleware(['honey', 'honey-recaptcha']) ->name('company.send.message');

Using Laravel 8.16

I do have the recaptcha credentials in the env

@smc13
Copy link

smc13 commented Dec 22, 2020

Just ran into this.

Appears to be due to the checkToken call failing in the middleware, which then gets caught and attempts to call Honey::fail() which returns early due to being disabled in the environment.

Due to the checkToken call failing, there isn't a response set when the middleware reaches the isSpam check.

@lukeraymonddowning
Copy link
Owner

Going to have another look over the holidays 👍 thanks for the confirmation

@pravnkay
Copy link

I don't know if this is the real issue. I was getting the same error as @JamesCobbledick
My code was like this,

<form method='post' action='{{route("web.write-comment")}}'>
	@csrf
	<x-honey/>
	<x-honey-recaptcha action="save-comment"/>

Was getting these errors

21:37:34 error The following errors were returned from the recaptcha token: invalid-input-responseLukeraymonddowning\Honey\Exceptions\RecaptchaFailedExceptionRecaptcha.php:37
21:37:34 error Typed property Lukeraymonddowning\Honey\Captcha\Recaptcha::$response must not be accessed before initializationArray(1) exception: Errorexception: Error*message: "Typed property Lukeraymonddowning\Honey\Captcha\Recaptcha::$response must not be accessed before initialization"-string: ""code: 0file: "E:\Professional\laragon\www\finserv\vendor\lukeraymonddowning\honey\src\Captcha\Recaptcha.php"*line: 60~trace: Array(52)~previous: null

But, when I removed the action attribute in x-honey-recaptcha tag, the error was no longer showing up.
Just putting it out here so that it might help solve the problem, just in case.

Laravel : v8.75.0
Honey: v0.3.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants