Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: ignore case for email (#5754)

DarkSky1db801929252
diff --git a/packages/backend/server/src/core/auth/next-auth-options.ts b/packages/backend/server/src/core/auth/next-auth-options.ts
index db711c06d0..e6308f3f6e 100644
--- a/packages/backend/server/src/core/auth/next-auth-options.ts
+++ b/packages/backend/server/src/core/auth/next-auth-options.ts
@@ -244,7 +244,10 @@ export const NextAuthOptionsProvider: FactoryProvider<NextAuthOptions> = {
.count({
where: {
user: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
feature: {
feature: FeatureType.EarlyAccess,
diff --git a/packages/backend/server/src/core/auth/next-auth.controller.ts b/packages/backend/server/src/core/auth/next-auth.controller.ts
index a58d89c117..ab083845aa 100644
--- a/packages/backend/server/src/core/auth/next-auth.controller.ts
+++ b/packages/backend/server/src/core/auth/next-auth.controller.ts
@@ -107,7 +107,10 @@ export class NextAuthController {
if (email) {
const user = await this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
});
if (!user) {
diff --git a/packages/backend/server/src/core/auth/service.ts b/packages/backend/server/src/core/auth/service.ts
index 754c5b70aa..75d9890bde 100644
--- a/packages/backend/server/src/core/auth/service.ts
+++ b/packages/backend/server/src/core/auth/service.ts
@@ -151,7 +151,10 @@ export class AuthService {
async signIn(email: string, password: string): Promise<User> {
const user = await this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
});
@@ -179,7 +182,10 @@ export class AuthService {
async signUp(name: string, email: string, password: string): Promise<User> {
const user = await this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
});
@@ -213,7 +219,10 @@ export class AuthService {
async createAnonymousUser(email: string): Promise<User> {
const user = await this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
});
@@ -241,9 +250,12 @@ export class AuthService {
}
async getUserByEmail(email: string): Promise<User | null> {
- return this.prisma.user.findUnique({
+ return this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
});
}
@@ -251,7 +263,10 @@ export class AuthService {
async isUserHasPassword(email: string): Promise<boolean> {
const user = await this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
});
if (!user) {
@@ -261,9 +276,12 @@ export class AuthService {
}
async changePassword(email: string, newPassword: string): Promise<User> {
- const user = await this.prisma.user.findUnique({
+ const user = await this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
emailVerified: {
not: null,
},
diff --git a/packages/backend/server/src/core/features/management.ts b/packages/backend/server/src/core/features/management.ts
index dfccaa8919..e2e0f8c82c 100644
--- a/packages/backend/server/src/core/features/management.ts
+++ b/packages/backend/server/src/core/features/management.ts
@@ -50,7 +50,10 @@ export class FeatureManagementService {
async isEarlyAccessUser(email: string) {
const user = await this.prisma.user.findFirst({
where: {
- email,
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
},
});
if (user) {
diff --git a/packages/backend/server/src/core/users/users.ts b/packages/backend/server/src/core/users/users.ts
index 84a889fd1c..f733249f9a 100644
--- a/packages/backend/server/src/core/users/users.ts
+++ b/packages/backend/server/src/core/users/users.ts
@@ -7,13 +7,14 @@ export class UsersService {
constructor(private readonly prisma: PrismaService) {}
async findUserByEmail(email: string) {
- return this.prisma.user
- .findUnique({
- where: { email },
- })
- .catch(() => {
- return null;
- });
+ return this.prisma.user.findFirst({
+ where: {
+ email: {
+ equals: email,
+ mode: 'insensitive',
+ },
+ },
+ });
}
async findUserById(id: string) {