Skip to content

feat: add only option for authentication routes configuration#1323

Open
dimtrovich wants to merge 13 commits intocodeigniter4:developfrom
dimtrovich:feat/only-routes-options
Open

feat: add only option for authentication routes configuration#1323
dimtrovich wants to merge 13 commits intocodeigniter4:developfrom
dimtrovich:feat/only-routes-options

Conversation

@dimtrovich
Copy link
Copy Markdown

Description
This pull request adds the ability to specify only the authentication routes to include via a new only option in the routes() method.
In fact, if we only want the login, it would be easier to use ['only' => ['login']] than ['except' => ['register', 'logout', 'magic-link']]

Changes in Auth.php

  • New only option: Allows specifying a list of routes to include (opposite of except)
  • Mutual validation: Added a check to prevent the simultaneous use of only and except

Benefits of this change

  • Improved flexibility - Complements the except option by offering a reverse approach (whitelist vs. blacklist)
  • Intuitive API - Allows for a more concise configuration when few routes are needed

Usage examples

// Include only the login and logout routes
service('auth')->routes($routes, ['only' => ['login', 'logout']]);

// Exclude magic-link routes (opposite behavior)
service('auth')->routes($routes, ['except' => ['magic-link']]);

// Error - these two options

**Checklist:**
- [ ] Securely signed commits
- [ ] Component(s) with PHPDoc blocks, only if necessary or adds value
- [ ] Unit testing, with >80% coverage
- [ ] User guide updated
- [ ] Conforms to style guide

@michalsn
Copy link
Copy Markdown
Member

This looks useful, thanks.

@michalsn
Copy link
Copy Markdown
Member

Please rebase your branch onto upstream/develop. If you don't have an upstream remote configured, add it first and then run:

git rebase upstream/develop

@datamweb datamweb added GPG-Signing needed Pull requests that need GPG-Signing enhancement New feature or request labels Apr 23, 2026
@michalsn
Copy link
Copy Markdown
Member

michalsn commented May 8, 2026

Please follow the similar path as described here: #1322 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request GPG-Signing needed Pull requests that need GPG-Signing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants