Skip to content

Commit b2c32ef

Browse files
authored
Merge pull request #73 from UseMuffin/issue-71
Don't throw exception if user record is not found.
2 parents 28f404b + e81b516 commit b2c32ef

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
},
3535
"require-dev": {
3636
"cakephp/cakephp-codesniffer": "^4.0",
37-
"phpunit/phpunit": "~8.5.0"
37+
"phpunit/phpunit": "~8.5.0",
38+
"cakephp/authentication": "^2.3"
3839
},
3940
"scripts": {
4041
"cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",

src/Auth/FootprintAwareTrait.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
namespace Muffin\Footprint\Auth;
55

6+
use Authentication\IdentityInterface;
67
use Cake\Datasource\EntityInterface;
78
use Cake\Event\EventInterface;
89
use Cake\Event\EventManager;
910
use Muffin\Footprint\Event\FootprintListener;
10-
use RuntimeException;
1111

12+
/**
13+
* @property \Cake\Http\ServerRequest $request
14+
*/
1215
trait FootprintAwareTrait
1316
{
1417
/**
@@ -107,10 +110,11 @@ protected function _setCurrentUser($user = null): ?EntityInterface
107110
}
108111
} elseif ($this->components()->has('Auth')) {
109112
$user = $this->Auth->user();
110-
} elseif ($this->name !== 'Error') {
111-
throw new RuntimeException(
112-
'You must have AuthenticationComponent or AuthComponent loaded to use Footprint'
113-
);
113+
} else {
114+
$identity = $this->request->getAttribute('identity');
115+
if ($identity && $identity instanceof IdentityInterface) {
116+
$user = $identity->getOriginalData();
117+
}
114118
}
115119
}
116120

0 commit comments

Comments
 (0)