codeigniter4 / shield

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

Bug: Incorrect operation of command `shield:setup` if there is `// service('auth')->routes();` #699

Closed datamweb closed 1 year ago

datamweb commented 1 year ago

PHP Version

8.1.5

CodeIgniter4 Version

4.3.2

Shield Version

dev

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

MySQL

Did you customize Shield?

No.

What happened?

Command shield:setup does not correctly update file app/Config/Routes.php if there is //service('auth')->routes($routes); or // service('auth')->routes($routes);.

Steps to Reproduce

Adding the following to file app/Config/Routes.php:

// service('auth')->routes($routes);

Or

//service('auth')->routes($routes);

run :

php spark shield:setup
CodeIgniter v4.3.2 Command Line Tool - Server Time: 2023-04-11 18:33:42 UTC+04:30

  File 'APPPATH\Config\Auth.php' already exists in destination. Overwrite? [n, y]: y
  Created: APPPATH\Config\Auth.php
  File 'APPPATH\Config\AuthGroups.php' already exists in destination. Overwrite? [n, y]: y
  Created: APPPATH\Config\AuthGroups.php
  Skipped APPPATH\Controllers\BaseController.php. It has already been updated.
  Skipped APPPATH\Config\Routes.php. It has already been updated.
  Security Setup: Everything is fine.
  Run `spark migrate --all` now? [y, n]: y
Running all new migrations...
Migrations complete.

See file app/Config/Routes.php, service('auth')->routes($routes); is not added.

Expected Output

If there are //service('auth')->routes($routes); or // service('auth')->routes($routes);, either leave the comment mode or add a new service('auth')->routes($routes); to the file.

Anything else?

No response

kenjis commented 1 year ago

Do you really need the Expected Output? Eventually, it will be necessary to parse the Config file to find the tokens.

/* service('auth')->routes($routes); */

/* 
service('auth')->routes($routes);
*/

# service('auth')->routes($routes);
datamweb commented 1 year ago

Do you really need the Expected Output?

Kenjis I was developing a project when I found out about this completely by accident. The fact is, in my opinion, it is not an important issue, however, I reported it so that I don't forget. I will close the topic now, if it is reported by someone else, it will be followed up.