Skip to content

Commit e17a042

Browse files
authored
Merge pull request #1160 from kenjis/fix-ChainAuth-last_active
fix: `chain` filter does not update `last_active`
2 parents d3b9285 + 566ef50 commit e17a042

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Config/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class Auth extends BaseConfig
160160
* --------------------------------------------------------------------
161161
* If true, will always update the `last_active` datetime for the
162162
* logged-in user on every page request.
163-
* This feature only works when session/tokens filter is active.
163+
* This feature only works when session/tokens/hmac/chain/jwt filter is active.
164164
*
165165
* @see https://codeigniter4.github.io/shield/quick_start_guide/using_session_auth/#protecting-pages for set filters.
166166
*/

src/Filters/ChainAuth.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use CodeIgniter\HTTP\IncomingRequest;
1818
use CodeIgniter\HTTP\RedirectResponse;
1919
use CodeIgniter\HTTP\RequestInterface;
20-
use CodeIgniter\HTTP\Response;
2120
use CodeIgniter\HTTP\ResponseInterface;
2221

2322
/**
@@ -29,14 +28,8 @@
2928
class ChainAuth implements FilterInterface
3029
{
3130
/**
32-
* Do whatever processing this filter needs to do.
33-
* By default it should not return anything during
34-
* normal execution. However, when an abnormal state
35-
* is found, it should return an instance of
36-
* CodeIgniter\HTTP\Response. If it does, script
37-
* execution will end and that Response will be
38-
* sent back to the client, allowing for error pages,
39-
* redirects, etc.
31+
* Checks authenticators in sequence to see if the user is logged in through
32+
* either of authenticators.
4033
*
4134
* @param array|null $arguments
4235
*
@@ -53,10 +46,18 @@ public function before(RequestInterface $request, $arguments = null)
5346
$chain = config('Auth')->authenticationChain;
5447

5548
foreach ($chain as $alias) {
56-
if (auth($alias)->loggedIn()) {
49+
$auth = auth($alias);
50+
51+
if ($auth->loggedIn()) {
5752
// Make sure Auth uses this Authenticator
5853
auth()->setAuthenticator($alias);
5954

55+
$authenticator = $auth->getAuthenticator();
56+
57+
if (setting('Auth.recordActiveDate')) {
58+
$authenticator->recordActiveDate();
59+
}
60+
6061
return;
6162
}
6263
}

0 commit comments

Comments
 (0)