fix(core): Make email for UM case insensitive (#3078)
* 🚧 lowercasing email * ✅ add tests for case insensitive email * 🐘 add migration to lowercase email * 🚚 rename migration * 🐛 fix package.lock * 🐛 fix double import * 📋 add todo
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
BeforeInsert,
|
||||
} from 'typeorm';
|
||||
import { IsEmail, IsString, Length } from 'class-validator';
|
||||
import * as config from '../../../config';
|
||||
@@ -20,7 +21,7 @@ import { Role } from './Role';
|
||||
import { SharedWorkflow } from './SharedWorkflow';
|
||||
import { SharedCredentials } from './SharedCredentials';
|
||||
import { NoXss } from '../utils/customValidators';
|
||||
import { answersFormatter } from '../utils/transformers';
|
||||
import { answersFormatter, lowerCaser } from '../utils/transformers';
|
||||
|
||||
export const MIN_PASSWORD_LENGTH = 8;
|
||||
|
||||
@@ -62,7 +63,11 @@ export class User {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ length: 254, nullable: true })
|
||||
@Column({
|
||||
length: 254,
|
||||
nullable: true,
|
||||
transformer: lowerCaser,
|
||||
})
|
||||
@Index({ unique: true })
|
||||
@IsEmail()
|
||||
email: string;
|
||||
@@ -119,8 +124,10 @@ export class User {
|
||||
})
|
||||
updatedAt: Date;
|
||||
|
||||
@BeforeInsert()
|
||||
@BeforeUpdate()
|
||||
setUpdateDate(): void {
|
||||
preUpsertHook(): void {
|
||||
this.email = this.email?.toLowerCase();
|
||||
this.updatedAt = new Date();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user