codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
366 stars 133 forks source link

Bug: Call to undefined function CodeIgniter\Shield\Filters\auth() #914

Closed mshannaq closed 1 year ago

mshannaq commented 1 year ago

PHP Version

8.1.8

CodeIgniter4 Version

4.4.

Shield Version

dev-develop 0cd5f3f

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

MySQL

Did you customize Shield?

No

What happened?

I was on shiled (dev-develop 189017e) and it was working fine

after updating to dev-develop 0cd5f3f I got the error

Call to undefined function CodeIgniter\Shield\Filters\auth()

VENDORPATH/codeigniter4/shield/src/Filters/SessionAuth.php at line 43

36     public function before(RequestInterface $request, $arguments = null)
37     {
38         if (! $request instanceof IncomingRequest) {
39             return;
40         }
41 
42         /** @var Session $authenticator */
43         $authenticator = auth('session')->getAuthenticator();
44 
45         if ($authenticator->loggedIn()) {
46             if (setting('Auth.recordActiveDate')) {
47                 $authenticator->recordActiveDate();
48             }
49 
50             // Block inactive users when Email A

Tracing:

  1. SYSTEMPATH/Filters/Filters.php : 182 — CodeIgniter\Shield\Filters\SessionAuth->before ()
175             if (! $class instanceof FilterInterface) {
176                 throw FilterException::forIncorrectInterface(get_class($class));
177             }
178 
179             if ($position === 'before') {
180                 $result = $class->before(
181                     $this->request,
182                     $this->argumentsClass[$className] ?? null
183                 );
184 
185                 if ($result instanceof RequestInterface) {
186                     $this->request = $result;
187 
188                     continue;
189                 }

2. SYSTEMPATH/CodeIgniter.php : 466 — CodeIgniter\Filters\Filters->run ()

459                     $filters->enableFilter($routeFilter, 'before');
460                     $filters->enableFilter($routeFilter, 'after');
461                 }
462             }
463 
464             // Run "before" filters
465             $this->benchmark->start('before_filters');
466             $possibleResponse = $filters->run($uri, 'before');
467             $this->benchmark->stop('before_filters');
468 
469             // If a ResponseInterface instance is returned then send it back to the client and stop
470             if ($possibleResponse instanceof ResponseInterface) {
471                 $this->outputBufferingEnd();
472 
473                 return $possibleResponse;

3.SYSTEMPATH/CodeIgniter.php : 353 — CodeIgniter\CodeIgniter->handleRequest ()

346 
347         $this->getRequestObject();
348         $this->getResponseObject();
349 
350         $this->spoofRequestMethod();
351 
352         try {
353             $this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
354         } catch (ResponsableInterface|DeprecatedRedirectException $e) {
355             $this->outputBufferingEnd();
356             if ($e instanceof DeprecatedRedirectException) {
357                 $e = new RedirectException($e->getMessage(), $e->getCode(), $e);
358             }
359 
360             $this->response = $e->getResponse();

4. FCPATH/index.php : 79 — CodeIgniter\CodeIgniter->run ()

72  *---------------------------------------------------------------
73  * LAUNCH THE APPLICATION
74  *---------------------------------------------------------------
75  * Now that everything is set up, it's time to actually fire
76  * up the engines and make this app do its thang.
77  */
78 
79 $app->run();
80 
81 // Save Config Cache
82 // $factoriesCache->save('config');
83 // ^^^ Uncomment this line if you want to use Config Caching.
84 
85 // Exits the application, setting the exit code for CLI-based applications
86 // that might be watching.

Steps to Reproduce

after updating to dev-develop 0cd5f3f I got the error

Call to undefined function CodeIgniter\Shield\Filters\auth()

Expected Output

Normal

Anything else?

No response

datamweb commented 1 year ago

https://github.com/codeigniter4/shield/blob/develop/UPGRADING.md#version-100-beta7-to-100-beta8

mshannaq commented 1 year ago

Thanks a lot!

fixed after I did

php spark shield:setup