Adds loginHandler to dbAuth for custom login checks #3111
Merged
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.
This adds two feature requests to dbAuth:
1. New
loginHandler()
By throwing an error with a message in the new
loginHandler()
option, you can deny them access and show a message:2.
signupHandler()
UpdatesIf you return a user from this function then that user will be signed in.
If you return a string, they will NOT be logged in, and
{message: "My text here"}
will be returned when you call thesignUp()
function that you get fromuseAuth()
.If you throw an error,
{error: "Error message"}
will be returned fromsignUp()
.Breaking Changes
api/src/functions/auth.js
This will require that users who have implemented dbAuth since the last release add a
loginHandler()
function in theirapi/src/functions/auth.js
setup.A new instance of
DbAuthHandler
is created and passed several options.loginHandler()
needs to be added to that list:No changes are necessary to
signupHandler()
as this is NEW functionality and existing functionality (returning a user or throw an error) is preserved.Login/Signup Components
The response from
signUp()
is now an object with anerror
key if there was an error, or amessage
key ifsignupHandler()
returns a string. Previously, error messages were returned with amessage
key only.If a user is returned and logged in, an object is returned with an
id
key containing theid
of the user.Docs
Generated functions and components have updated comments explaining what to return in these function in various circumstances. redwoodjs.com doc updates are coming that explain these same changes.
Closes #3064