google2fa-laravel
google2fa-laravel copied to clipboard
Middleware does not work in tests
The included middleware '2fa' does not seem to work in tests.
I have added the middleware to app/Http/Kernel.php and am using it in my API. All my test users have google2fa secret generated in factory.
Still nothing happens - the middleware does not request for 2FA token nor does it stop the routes from being taken, it seems that the middleware does not to anything at all.
I have tried both stateful and stateless middleware.
Tracking down, the middleware function noUserIsAuthenticated() returns true, thus the middleware does not detect my authentication.
If I change the code as follows to see which check fails:
protected function canPassWithoutCheckingOTP()
{
if(!$this->isEnabled()) { echo "2FA not enabled...\n";}
if($this->noUserIsAuthenticated()) {echo "user is not authenticated...\n";}
if(!$this->isActivated()) {echo "user is not authenticated...\n";}
if($this->twoFactorAuthStillValid()) {echo "two factor auth is still valid...\n";}
return
!$this->isEnabled() ||
$this->noUserIsAuthenticated() ||
!$this->isActivated() ||
$this->twoFactorAuthStillValid();
}
I get the output user is not authenticated... and the following error:
ErrorException: Trying to get property 'google2fa_secret' of non-object
The error does not happen without those changes above.
Any clue what might be wrong?
Same here, were you able to fix it @ValtteriL ?
No, unfortunately not. @Tiththa