Skip to content

Commit

Permalink
fix: lowercase emails in db (#8326)
Browse files Browse the repository at this point in the history
* fix: lowercase emails in db

* r

---------

Co-authored-by: Henry Fontanier <[email protected]>
  • Loading branch information
fontanierh and Henry Fontanier authored Oct 30, 2024
1 parent 38ae4e6 commit 1ca19b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions front/lib/resources/user_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class UserResource extends BaseResource<User> {
> &
Partial<Pick<Attributes<User>, "providerId" | "imageUrl">>
): Promise<UserResource> {
const user = await User.create(blob);
const lowerCaseEmail = blob.email?.toLowerCase();
const user = await User.create({ ...blob, email: lowerCaseEmail });
return new this(User, user.get());
}

Expand Down Expand Up @@ -104,7 +105,7 @@ export class UserResource extends BaseResource<User> {
static async fetchByEmail(email: string): Promise<UserResource | null> {
const user = await User.findOne({
where: {
email,
email: email.toLowerCase(),
},
});

Expand Down Expand Up @@ -227,8 +228,9 @@ export class UserResource extends BaseResource<User> {
lastName: string | null,
email: string
): Promise<void> {
const lowerCaseEmail = email.toLowerCase();
const [, affectedRows] = await this.model.update(
{ username, firstName, lastName, email },
{ username, firstName, lastName, email: lowerCaseEmail },
{
where: {
id: this.id,
Expand Down
6 changes: 6 additions & 0 deletions front/migrations/20241030_lowercase_emails.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UPDATE
users
SET
email = LOWER(email)
WHERE
email <> LOWER(email);

0 comments on commit 1ca19b5

Please sign in to comment.