-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth v3 #26
Closed
Closed
Auth v3 #26
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closing as merged |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce? (pls check at least one)
Description
This PR introduces a cleaner end-user experience to working with authentication in Leaf. It normalizes the configuration and removes options for some configuration that should be default as well as simplifying the available options and making them easier to use.
V3 also introduces an improved DX for working with middleware, removes the numerous redirect options and removes session guards as well. Session and token auth is more normalized, leaving side effects to you instead of trying to anticipate what you want to do (to the detriment of other users).
Beyond these changes, we've maintained every other thing v2 came with which means if you had no custom config and didn't use session guards, you can upgrade to v3 with almost zero changes to your existing code.
Change Examples
This will now look like:
This is easier to read and write and also allows you to share unique items between
register()
andupdate()
which is usually what you would want to do.Auth v3 comes with built-in middleware that integrates with Leaf which means you don't need to write the above or your own middleware or even use guards:
The updated user object is more powerful and makes sure that the authenticated user is always in scope when it should be which was not the case in the previous version.
Before:
Now:
This makes sure that behaviour is consistent
The update user object also allows you to build queries directly by extending Leaf DB when a relationship is available. For instance, if a user has many blog posts in the
articles
db column, you can get them using Leaf auth directly:Before:
After:
When you call any method that doesn't exist on the user object, Leaf Auth will assume that you mean to get data related to the current user from the database. This still uses Leaf DB, so you don't need to learn any additional syntax. If you want to do additional filtering, you can add a where block or anything you need.
Back to the user object, it used to return an array which was the user information without any hidden fields. This behaviour has been updated to now return an entire user class. This class has methods and properties for getting user data, tokens and related db as we saw above:
Picking specific fields using the user object gives you access to hidden fields which means you can do something like this:
This is allowed because once again, we assume that a single value you pick is going to be used within your application which should not be a security issue.
Does this PR introduce a breaking change? (check one)
Related Issue
None