Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

made the email field case-insensitive

Danielddc0675d2e06
diff --git a/lib/api/controllers/collections/postCollection.ts b/lib/api/controllers/collections/postCollection.ts
index c6735e4a..6229a869 100644
--- a/lib/api/controllers/collections/postCollection.ts
+++ b/lib/api/controllers/collections/postCollection.ts
@@ -42,7 +42,7 @@ export default async function postCollection(
color: collection.color,
members: {
create: collection.members.map((e) => ({
- user: { connect: { email: e.user.email } },
+ user: { connect: { email: e.user.email.toLowerCase() } },
canCreate: e.canCreate,
canUpdate: e.canUpdate,
canDelete: e.canDelete,
diff --git a/lib/api/controllers/collections/updateCollection.ts b/lib/api/controllers/collections/updateCollection.ts
index b476eec8..963027f7 100644
--- a/lib/api/controllers/collections/updateCollection.ts
+++ b/lib/api/controllers/collections/updateCollection.ts
@@ -43,7 +43,7 @@ export default async function updateCollection(
isPublic: collection.isPublic,
members: {
create: collection.members.map((e) => ({
- user: { connect: { email: e.user.email } },
+ user: { connect: { email: e.user.email.toLowerCase() } },
canCreate: e.canCreate,
canUpdate: e.canUpdate,
canDelete: e.canDelete,
diff --git a/lib/api/controllers/users/getUsers.ts b/lib/api/controllers/users/getUsers.ts
index b587a27d..17d9a0fe 100644
--- a/lib/api/controllers/users/getUsers.ts
+++ b/lib/api/controllers/users/getUsers.ts
@@ -7,7 +7,7 @@ export default async function getUser(
) {
const user = await prisma.user.findUnique({
where: {
- email: lookupEmail,
+ email: lookupEmail.toLowerCase(),
},
});
@@ -16,7 +16,7 @@ export default async function getUser(
if (
!isSelf &&
user?.isPrivate &&
- !user.whitelistedUsers.includes(userEmail)
+ !user.whitelistedUsers.includes(userEmail.toLowerCase())
) {
return { response: "This profile is private.", status: 401 };
}
diff --git a/lib/api/controllers/users/updateUser.ts b/lib/api/controllers/users/updateUser.ts
index 08381417..70b86869 100644
--- a/lib/api/controllers/users/updateUser.ts
+++ b/lib/api/controllers/users/updateUser.ts
@@ -72,7 +72,7 @@ export default async function updateUser(
},
data: {
name: user.name,
- email: user.email,
+ email: user.email.toLowerCase(),
isPrivate: user.isPrivate,
whitelistedUsers: user.whitelistedUsers,
},
diff --git a/lib/client/addMemberToCollection.ts b/lib/client/addMemberToCollection.ts
index a3f831b1..608bbeeb 100644
--- a/lib/client/addMemberToCollection.ts
+++ b/lib/client/addMemberToCollection.ts
@@ -9,8 +9,8 @@ const addMemberToCollection = async (
setMember: (newMember: Member) => null | undefined
) => {
const checkIfMemberAlreadyExists = collection.members.find((e) => {
- const email = e.user.email;
- return email === memberEmail;
+ const email = e.user.email.toLowerCase();
+ return email === memberEmail.toLowerCase();
});
if (
@@ -22,7 +22,9 @@ const addMemberToCollection = async (
memberEmail.trim() !== ownerEmail
) {
// Lookup, get data/err, list ...
- const user = await getPublicUserDataByEmail(memberEmail.trim());
+ const user = await getPublicUserDataByEmail(
+ memberEmail.trim().toLowerCase()
+ );
if (user.email) {
setMember({
diff --git a/lib/client/getPublicUserDataByEmail.ts b/lib/client/getPublicUserDataByEmail.ts
index 3a34ae16..7829ab1b 100644
--- a/lib/client/getPublicUserDataByEmail.ts
+++ b/lib/client/getPublicUserDataByEmail.ts
@@ -1,7 +1,9 @@
import { toast } from "react-hot-toast";
export default async function getPublicUserDataByEmail(email: string) {
- const response = await fetch(`/api/routes/users?email=${email}`);
+ const response = await fetch(
+ `/api/routes/users?email=${email.toLowerCase()}`
+ );
const data = await response.json();
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts
index 6f91ca64..c950295e 100644
--- a/pages/api/auth/[...nextauth].ts
+++ b/pages/api/auth/[...nextauth].ts
@@ -21,7 +21,7 @@ export const authOptions: AuthOptions = {
const findUser = await prisma.user.findFirst({
where: {
- email: email,
+ email: email.toLowerCase(),
},
});
@@ -35,7 +35,7 @@ export const authOptions: AuthOptions = {
return {
id: findUser?.id,
name: findUser?.name,
- email: findUser?.email,
+ email: findUser?.email.toLowerCase(),
};
} else return null as any;
},
@@ -55,7 +55,7 @@ export const authOptions: AuthOptions = {
if (trigger === "update" && session?.name && session?.email) {
// Note, that `session` can be any arbitrary object, remember to validate it!
token.name = session.name;
- token.email = session.email;
+ token.email = session.email.toLowerCase();
}
return token;
},
diff --git a/pages/api/auth/register.ts b/pages/api/auth/register.ts
index 01fedf53..17a1a598 100644
--- a/pages/api/auth/register.ts
+++ b/pages/api/auth/register.ts
@@ -25,7 +25,7 @@ export default async function Index(
const checkIfUserExists = await prisma.user.findFirst({
where: {
- email: body.email,
+ email: body.email.toLowerCase(),
},
});
@@ -37,7 +37,7 @@ export default async function Index(
await prisma.user.create({
data: {
name: body.name,
- email: body.email,
+ email: body.email.toLowerCase(),
password: hashedPassword,
},
});
diff --git a/pages/api/avatar/[id].ts b/pages/api/avatar/[id].ts
index dd129ea6..23521f4b 100644
--- a/pages/api/avatar/[id].ts
+++ b/pages/api/avatar/[id].ts
@@ -8,7 +8,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
const session = await getServerSession(req, res, authOptions);
const userId = session?.user.id;
- const userEmail = session?.user.email;
+ const userEmail = session?.user.email?.toLowerCase();
const queryId = Number(req.query.id);
if (!queryId)