I've found out, that my Laravel (5.7) App has a strange behavior in some case where it performs two requests of form submits. Last week everything worked fine.
E.g: There is a registration form. When a user wants to register and submits the form, he fails validation, because the entered email-address already exists (which it doesn't right before he submitted the form). A glance in my database shows me, that the user was created and logged in. So it seems, that the form somehow performs two requests.
This behavior happens on several forms all over the application but not on all. This causes some very bad actions (the one above, emails are sent double, images are uploaded twice etc etc).
One possible problem-causer could be a new Middleware, where I access the current request and perform some actions on it:
class CookiebannerMiddleware
{
public function handle(Request $request, Closure $next)
{
$cookie_name = config('cookiebanner.cookie_key');
$cookie_value = config('cookiebanner.cookie_value');
$cookie_lifetime = config('cookiebanner.cookie_lifetime');
$response = $next($request);
if(!$request->hasCookie($cookie_name)){
$response->cookie($cookie_name, $cookie_value, $cookie_lifetime);
return $response;
}
return $next($request);
}
}
Or are there any other possibilities which could cause such problems?
Update
The problem was my CookiebannerMiddleware. The problem is fixed with the following solution:
class CookiebannerMiddleware
{
public function handle(Request $request, Closure $next)
{
$cookie_name = config('cookiebanner.cookie_key');
$cookie_value = config('cookiebanner.cookie_value');
$cookie_lifetime = config('cookiebanner.cookie_lifetime');
if(!$request->hasCookie($cookie_name)){
return $next($request)->withCookie($cookie_name, $cookie_value, $cookie_lifetime);
}
return $next($request);
}
}