[PR #1268] [CLOSED] Case-Insensitive Email Handling and Improve OAuth Login #1782

Closed
opened 2026-03-02 11:59:09 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/karakeep-app/karakeep/pull/1268
Author: @ChaoticSciuridae
Created: 4/15/2025
Status: Closed

Base: mainHead: auth/case-insensitive-email


📝 Commits (5)

  • 21a97b2 overide Drizzle GetUserByEmail to query lowercase
  • 8ede8fe for credential login query database for lowercase
  • d23a518 for credential login query database for lowercase
  • f8d65a7 updated schema with unique email index
  • bc27c8e added comments

📊 Changes

4 files changed (+140 additions, -15 deletions)

View changed files

📝 apps/web/server/auth.ts (+71 -11)
apps/web/server/custom-adapter.ts (+36 -0)
📝 packages/db/schema.ts (+27 -2)
📝 packages/trpc/auth.ts (+6 -2)

📄 Description

This pull request addresses issues related to email case sensitivity and OAuth login in the Karakeep app, ensuring compliance with RFC 2821 recommendations for email handling and improving user experience. It resolves Issue #410 (duplicate accounts due to case-sensitive emails) and Issue #411 (login failures and OAuth data issues).

Changes

  1. Case-Insensitive Unique Index on Email:

    • Added a unique index on the email field in the database, treating emails case-insensitively (e.g., JaneDoe@domain.com and janedoe@domain.com are considered the same).
    • Prevents creation of duplicate accounts going forward.
    • Note: Currently, users must delete duplicates before upgrading. If duplicate accounts already exist (e.g., JaneDoe@domain.com and janedoe@domain.com), this will prevent Karakeep from starting. with an unclear error message. Detection of duplicates, and a migration path forward probably should be added.
  2. Improved OAuth Login:

    • Modified OAuth login to query the userinfo endpoint instead of relying solely on token_id.
    • Provides more complete user information, reducing cases where the name field falls back to the email address.
    • When fallback is necessary, the name is derived from the Local-part of the email (e.g., JaneDoe from JaneDoe@domain.com).
  3. Case-Insensitive Login:

    • Updated login logic to allow users to log in regardless of the case used in their email address (e.g., JanDoe@domain.com or jandoe@domain.com).
  4. Preserve Displayed Email Case:

    • The database retains the email case as entered by the user (e.g., JanDoe@domain.com continues to display as such), while enforcing case-insensitive uniqueness.

Why This Matters

Per RFC 2821:

  • The Local-part of an email address may be case-sensitive, but for interoperability, mail systems should treat it as case-insensitive unless explicitly required.
  • The Domain part is always case-insensitive per DNS standards.
  • Most modern email providers treat emails as case-insensitive to avoid confusion.
  • These changes align Karakeep with these best practices, preventing duplicate accounts and ensuring seamless login experiences.

Issues Resolved

  • Issue #410: Duplicate accounts caused by case-sensitive email handling.
  • Issue #411: Login failures due to case mismatches and incomplete OAuth user data.

Checklist

  • Added case-insensitive unique index on email.
  • Updated OAuth login to use userinfo endpoint.
  • Enabled case-insensitive login.
  • Preserved displayed email case.
  • Test with multiple OAuth providers
  • Add migration script for duplicates.
  • Add error handling: If the unique index creation fails due to duplicates, provide a user-friendly error message.

Testing

  • Verified that new accounts cannot be created with case variants of existing emails.
  • Tested login with various email case combinations (e.g., JanDoe@domain.com, jandoe@domain.com).
  • Confirmed OAuth login retrieves complete user data from the userinfo endpoint.
  • Confirmed dangerousAccountLinking works with different case.
  • Validated that displayed email case is preserved in the UI.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/karakeep-app/karakeep/pull/1268 **Author:** [@ChaoticSciuridae](https://github.com/ChaoticSciuridae) **Created:** 4/15/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `auth/case-insensitive-email` --- ### 📝 Commits (5) - [`21a97b2`](https://github.com/karakeep-app/karakeep/commit/21a97b243ef33c6a32605efbe01a870ecaf2b8d4) overide Drizzle GetUserByEmail to query lowercase - [`8ede8fe`](https://github.com/karakeep-app/karakeep/commit/8ede8feef19ee808ff668f1535fb01554830bdae) for credential login query database for lowercase - [`d23a518`](https://github.com/karakeep-app/karakeep/commit/d23a5188bdc3000693a8f0ccb0bb8c7b4be0d203) for credential login query database for lowercase - [`f8d65a7`](https://github.com/karakeep-app/karakeep/commit/f8d65a74183d71354443ef8957d2e905134fb5cd) updated schema with unique email index - [`bc27c8e`](https://github.com/karakeep-app/karakeep/commit/bc27c8ecedbb8ef55e9575273028dd4907187a7a) added comments ### 📊 Changes **4 files changed** (+140 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `apps/web/server/auth.ts` (+71 -11) ➕ `apps/web/server/custom-adapter.ts` (+36 -0) 📝 `packages/db/schema.ts` (+27 -2) 📝 `packages/trpc/auth.ts` (+6 -2) </details> ### 📄 Description This pull request addresses issues related to email case sensitivity and OAuth login in the Karakeep app, ensuring compliance with RFC 2821 recommendations for email handling and improving user experience. It resolves [Issue #410](https://github.com/karakeep-app/karakeep/issues/410#issuecomment-2740961459) (duplicate accounts due to case-sensitive emails) and [Issue #411](https://github.com/karakeep-app/karakeep/issues/411#issuecomment-2744976404) (login failures and OAuth data issues). ## Changes 1. **Case-Insensitive Unique Index on Email**: - Added a unique index on the `email` field in the database, treating emails case-insensitively (e.g., `JaneDoe@domain.com` and `janedoe@domain.com` are considered the same). - Prevents creation of duplicate accounts going forward. - **Note**: Currently, users must delete duplicates before upgrading. If duplicate accounts already exist (e.g., `JaneDoe@domain.com` and `janedoe@domain.com`), this will prevent Karakeep from starting. with an unclear error message. Detection of duplicates, and a migration path forward probably should be added. 2. **Improved OAuth Login**: - Modified OAuth login to query the `userinfo` endpoint instead of relying solely on `token_id`. - Provides more complete user information, reducing cases where the `name` field falls back to the email address. - When fallback is necessary, the `name` is derived from the **Local-part** of the email (e.g., `JaneDoe` from `JaneDoe@domain.com`). 3. **Case-Insensitive Login**: - Updated login logic to allow users to log in regardless of the case used in their email address (e.g., `JanDoe@domain.com` or `jandoe@domain.com`). 4. **Preserve Displayed Email Case**: - The database retains the email case as entered by the user (e.g., `JanDoe@domain.com` continues to display as such), while enforcing case-insensitive uniqueness. ## Why This Matters Per RFC 2821: - The **Local-part** of an email address *may* be case-sensitive, but for interoperability, mail systems should treat it as case-insensitive unless explicitly required. - The **Domain** part is always case-insensitive per DNS standards. - Most modern email providers treat emails as case-insensitive to avoid confusion. - These changes align Karakeep with these best practices, preventing duplicate accounts and ensuring seamless login experiences. ## Issues Resolved - **Issue #410**: Duplicate accounts caused by case-sensitive email handling. - **Issue #411**: Login failures due to case mismatches and incomplete OAuth user data. ## Checklist - [x] Added case-insensitive unique index on `email`. - [x] Updated OAuth login to use `userinfo` endpoint. - [x] Enabled case-insensitive login. - [x] Preserved displayed email case. - [ ] Test with multiple OAuth providers - [ ] Add migration script for duplicates. - [ ] Add error handling: If the unique index creation fails due to duplicates, provide a user-friendly error message. ## Testing - Verified that new accounts cannot be created with case variants of existing emails. - Tested login with various email case combinations (e.g., `JanDoe@domain.com`, `jandoe@domain.com`). - Confirmed OAuth login retrieves complete user data from the `userinfo` endpoint. - Confirmed dangerousAccountLinking works with different case. - Validated that displayed email case is preserved in the UI. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 11:59:09 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/karakeep#1782
No description provided.