feat: ignore case for email (#5754)

fix #5738
This commit is contained in:
DarkSky
2024-02-01 05:05:16 +00:00
parent 349f7c3f15
commit 1db8019292
5 changed files with 46 additions and 18 deletions

View File

@@ -244,7 +244,10 @@ export const NextAuthOptionsProvider: FactoryProvider<NextAuthOptions> = {
.count({ .count({
where: { where: {
user: { user: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
feature: { feature: {
feature: FeatureType.EarlyAccess, feature: FeatureType.EarlyAccess,

View File

@@ -107,7 +107,10 @@ export class NextAuthController {
if (email) { if (email) {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
}); });
if (!user) { if (!user) {

View File

@@ -151,7 +151,10 @@ export class AuthService {
async signIn(email: string, password: string): Promise<User> { async signIn(email: string, password: string): Promise<User> {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
}); });
@@ -179,7 +182,10 @@ export class AuthService {
async signUp(name: string, email: string, password: string): Promise<User> { async signUp(name: string, email: string, password: string): Promise<User> {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
}); });
@@ -213,7 +219,10 @@ export class AuthService {
async createAnonymousUser(email: string): Promise<User> { async createAnonymousUser(email: string): Promise<User> {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
}); });
@@ -241,9 +250,12 @@ export class AuthService {
} }
async getUserByEmail(email: string): Promise<User | null> { async getUserByEmail(email: string): Promise<User | null> {
return this.prisma.user.findUnique({ return this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
}); });
} }
@@ -251,7 +263,10 @@ export class AuthService {
async isUserHasPassword(email: string): Promise<boolean> { async isUserHasPassword(email: string): Promise<boolean> {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
}); });
if (!user) { if (!user) {
@@ -261,9 +276,12 @@ export class AuthService {
} }
async changePassword(email: string, newPassword: string): Promise<User> { async changePassword(email: string, newPassword: string): Promise<User> {
const user = await this.prisma.user.findUnique({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
emailVerified: { emailVerified: {
not: null, not: null,
}, },

View File

@@ -50,7 +50,10 @@ export class FeatureManagementService {
async isEarlyAccessUser(email: string) { async isEarlyAccessUser(email: string) {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email: {
equals: email,
mode: 'insensitive',
},
}, },
}); });
if (user) { if (user) {

View File

@@ -7,13 +7,14 @@ export class UsersService {
constructor(private readonly prisma: PrismaService) {} constructor(private readonly prisma: PrismaService) {}
async findUserByEmail(email: string) { async findUserByEmail(email: string) {
return this.prisma.user return this.prisma.user.findFirst({
.findUnique({ where: {
where: { email }, email: {
}) equals: email,
.catch(() => { mode: 'insensitive',
return null; },
}); },
});
} }
async findUserById(id: string) { async findUserById(id: string) {