Skip to content

feat: add only option for authentication routes configuration#1323

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

feat: add only option for authentication routes configuration#1323
dimtrovich wants to merge 3 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants