fix(auth): make login emails case-insensitive #2125
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.
Problem
#2084 introduced a bug where non-lowercase emails could not be used to log in to the admin dashboard.
The frontend used to mutate
vm.credentials.email
to lowercase at the point of sending the OTP, then use the lowercased string when subsequently verifying the OTP. This is important because the email domains in the Agencies collection are all in lowercase, so only lowercase email domains are considered to be valid. However, #2084 removed this mutation, resulting in OTP verification breaking for non-lowercase emails.This exposes a source of bugs in the authorisation flow, namely that the backend implicitly relies on the frontend to send email strings in the correct case.
Solution
For all authorisation endpoints, lowercase email addresses at the edge of the application using Joi validation. This ensures that there is no ambiguity about the case of the string at any layer of the backend.
Breaking Changes
Bug Fixes:
Login to admin dashboard is now case-insensitive for email addresses.
Tests
Integration tests were added to test the case-insensitivity of the authorisation endpoints.
Manual tests