|
20 | 20 | use CodeIgniter\Shield\Config\Auth as AuthConfig; |
21 | 21 | use CodeIgniter\Shield\Entities\User; |
22 | 22 | use CodeIgniter\Shield\Models\UserModel; |
| 23 | +use InvalidArgumentException; |
23 | 24 |
|
24 | 25 | /** |
25 | 26 | * Facade for Authentication |
@@ -134,13 +135,27 @@ public function authenticate(array $credentials): Result |
134 | 135 | */ |
135 | 136 | public function routes(RouteCollection &$routes, array $config = []): void |
136 | 137 | { |
| 138 | + if (isset($config['only'], $config['except'])) { |
| 139 | + throw new InvalidArgumentException( |
| 140 | + 'The "only" and "except" options cannot be used at the same time.', |
| 141 | + ); |
| 142 | + } |
| 143 | + |
137 | 144 | $authRoutes = config('AuthRoutes')->routes; |
138 | 145 |
|
139 | 146 | $namespace = $config['namespace'] ?? 'CodeIgniter\Shield\Controllers'; |
140 | 147 |
|
141 | 148 | $routes->group('/', ['namespace' => $namespace], static function (RouteCollection $routes) use ($authRoutes, $config): void { |
142 | 149 | foreach ($authRoutes as $name => $row) { |
143 | | - if (! isset($config['except']) || ! in_array($name, $config['except'], true)) { |
| 150 | + $shouldInclude = true; |
| 151 | + |
| 152 | + if (isset($config['only'])) { |
| 153 | + $shouldInclude = in_array($name, $config['only'], true); |
| 154 | + } elseif (isset($config['except'])) { |
| 155 | + $shouldInclude = ! in_array($name, $config['except'], true); |
| 156 | + } |
| 157 | + |
| 158 | + if ($shouldInclude) { |
144 | 159 | foreach ($row as $params) { |
145 | 160 | $options = isset($params[3]) |
146 | 161 | ? ['as' => $params[3]] |
|
0 commit comments