fix: make signin email case-insensitive #4048
Merged
mikecao merged 2 commits intoumami-software:devfrom Apr 2, 2026
Merged
Conversation
|
@AlejandroGispert is attempting to deploy a commit to the umami-software Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Greptile SummaryThis PR implements case-insensitive username authentication by normalizing usernames to lowercase on storage and lookup. The implementation includes:
The approach is sound and aligns with common authentication patterns. The PR requires a post-merge SQL migration to lowercase existing usernames in the database. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant LoginAPI as /api/auth/login
participant UserAPI as /api/users
participant UpdateAPI as /api/users/[userId]
participant getUserByUsername
participant createUser
participant updateUser
participant Database
Note over Client,Database: Login Flow (Case-Insensitive)
Client->>LoginAPI: POST {username: "Admin", password}
LoginAPI->>getUserByUsername: getUserByUsername("Admin")
getUserByUsername->>Database: SELECT WHERE username = "admin"
Database-->>getUserByUsername: user record
getUserByUsername-->>LoginAPI: user found
LoginAPI-->>Client: success + token
Note over Client,Database: User Creation
Client->>UserAPI: POST {username: "NewUser"}
UserAPI->>getUserByUsername: check exists ("NewUser")
getUserByUsername->>Database: SELECT WHERE username = "newuser"
Database-->>getUserByUsername: null
UserAPI->>createUser: createUser({username: "newuser"})
createUser->>Database: INSERT username = "newuser"
Database-->>UserAPI: user created
UserAPI-->>Client: success
Note over Client,Database: Username Update
Client->>UpdateAPI: POST {username: "ADMIN"}
UpdateAPI->>getUserByUsername: check exists ("ADMIN")
getUserByUsername->>Database: SELECT WHERE username = "admin"
Database-->>getUserByUsername: existing user found
UpdateAPI->>UpdateAPI: if existingUser.id != userId, reject
UpdateAPI->>updateUser: updateUser({username: "admin"})
updateUser->>Database: UPDATE username = "admin"
Database-->>UpdateAPI: user updated
UpdateAPI-->>Client: success
Last reviewed commit: 2ab5870 |
mikecao
approved these changes
Apr 2, 2026
This file contains hidden or 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
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.
Case-Insensitive Username Login, Closes #3981
Author: Alejandro Gispert
First-time contributor to Umami
Full documentation
Summary
This PR makes user login case-insensitive so that usernames like
Admin,admin, andADMINall resolve to the same account.Problem
Login was case-sensitive: a user created with username
admincould not log in by typingAdminorADMIN. This led to:Solution
Usernames are normalized to lowercase on storage and lookup:
Adminandadmincannot coexist).Changes
1.
src/queries/prisma/user.tsgetUserByUsername()– Normalizes the input withusername.toLowerCase()before querying, so lookups are case-insensitive.2.
src/app/api/auth/login/route.tsgetUserByUsername(), which now handles case-insensitivity.3.
src/app/api/users/route.tsusername.toLowerCase()when checking for existing users and when creating new users.4.
src/app/api/users/[userId]/route.tsusername.toLowerCase()when updating usernames.user(shadowing the current user), causing confusion. Renamed toexistingUser.Admintoadmin(same logical username) without being blocked.Post-merge: run this SQL
Existing users with mixed-case usernames must be updated. Run this against your database after merging:
Note: This will fail if there are case-variant duplicates (e.g. both
Adminandadmin). Resolve those manually before running.Testing
adminifAdminexists).Backward Compatibility