Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix: lowercase emails in endpoints that accept it

Mohamed Bassem6f56f74b3629
diff --git a/packages/trpc/routers/invites.ts b/packages/trpc/routers/invites.ts
index 27c343eb..6808484a 100644
--- a/packages/trpc/routers/invites.ts
+++ b/packages/trpc/routers/invites.ts
@@ -21,7 +21,7 @@ export const invitesAppRouter = router({
create: adminUsersProcedure
.input(
z.object({
- email: z.string().email(),
+ email: z.string().trim().toLowerCase().email(),
}),
)
.mutation(async ({ input, ctx }) => {
@@ -177,7 +177,7 @@ export const invitesAppRouter = router({
}
const existingUser = await ctx.db.query.users.findFirst({
- where: eq(users.email, invite.email),
+ where: eq(users.email, invite.email.toLowerCase()),
});
if (existingUser) {
diff --git a/packages/trpc/routers/lists.ts b/packages/trpc/routers/lists.ts
index 8f82931c..15fceba8 100644
--- a/packages/trpc/routers/lists.ts
+++ b/packages/trpc/routers/lists.ts
@@ -250,7 +250,7 @@ export const listsAppRouter = router({
.input(
z.object({
listId: z.string(),
- email: z.string().email(),
+ email: z.string().trim().toLowerCase().email(),
role: z.enum(["viewer", "editor"]),
}),
)
diff --git a/packages/trpc/routers/sharedLists.test.ts b/packages/trpc/routers/sharedLists.test.ts
index da336666..5f571813 100644
--- a/packages/trpc/routers/sharedLists.test.ts
+++ b/packages/trpc/routers/sharedLists.test.ts
@@ -95,6 +95,29 @@ describe("Shared Lists", () => {
).rejects.toThrow("Cannot add the list owner as a collaborator");
});
+ test<CustomTestContext>("should match collaborator email case-insensitively", async ({
+ apiCallers,
+ }) => {
+ const ownerApi = apiCallers[0];
+ const collaboratorApi = apiCallers[1];
+
+ const list = await ownerApi.lists.create({
+ name: "Test List",
+ icon: "📚",
+ type: "manual",
+ });
+
+ const collaboratorUser = await collaboratorApi.users.whoami();
+
+ const { invitationId } = await ownerApi.lists.addCollaborator({
+ listId: list.id,
+ email: ` ${collaboratorUser.email!.toUpperCase()} `,
+ role: "viewer",
+ });
+
+ await collaboratorApi.lists.acceptInvitation({ invitationId });
+ });
+
test<CustomTestContext>("should not allow adding duplicate collaborator", async ({
apiCallers,
}) => {
diff --git a/packages/trpc/routers/subscriptions.ts b/packages/trpc/routers/subscriptions.ts
index b1eb5f26..8cbf7830 100644
--- a/packages/trpc/routers/subscriptions.ts
+++ b/packages/trpc/routers/subscriptions.ts
@@ -604,7 +604,7 @@ export const subscriptionsRouter = router({
updateSubscriptionTier: adminSubscriptionsProcedure
.input(
z.object({
- email: z.string().email(),
+ email: z.string().trim().toLowerCase().email(),
manualTierName: z.string().trim().min(1).max(100).nullable(),
bookmarkQuota: z.number().int().min(0).nullable().optional(),
storageQuota: z.number().int().min(0).nullable().optional(),