From 677ead0ae41909ce721e9582c1993bf3ca35989d Mon Sep 17 00:00:00 2001 From: Dolly Date: Wed, 20 Mar 2024 19:51:19 +0530 Subject: [PATCH 1/2] fix(auth): E-Mail capitalization issue --- apps/client/src/pages/auth/forgot-password/page.tsx | 2 ++ apps/client/src/pages/auth/login/page.tsx | 2 ++ apps/client/src/pages/auth/register/page.tsx | 2 ++ 3 files changed, 6 insertions(+) diff --git a/apps/client/src/pages/auth/forgot-password/page.tsx b/apps/client/src/pages/auth/forgot-password/page.tsx index a69adb466..36ee94fd2 100644 --- a/apps/client/src/pages/auth/forgot-password/page.tsx +++ b/apps/client/src/pages/auth/forgot-password/page.tsx @@ -35,6 +35,8 @@ export const ForgotPasswordPage = () => { }); const onSubmit = async (data: FormValues) => { + //email convert to lowecase + data.email = data.email.toLowerCase(); await forgotPassword(data); setSubmitted(true); diff --git a/apps/client/src/pages/auth/login/page.tsx b/apps/client/src/pages/auth/login/page.tsx index 0b8ec0588..c603e18ca 100644 --- a/apps/client/src/pages/auth/login/page.tsx +++ b/apps/client/src/pages/auth/login/page.tsx @@ -41,6 +41,8 @@ export const LoginPage = () => { }); const onSubmit = async (data: FormValues) => { + //email/username convert to lowecase + data.identifier = data.identifier.toLowerCase(); try { await login(data); } catch (error) { diff --git a/apps/client/src/pages/auth/register/page.tsx b/apps/client/src/pages/auth/register/page.tsx index 75aad3151..508473ab4 100644 --- a/apps/client/src/pages/auth/register/page.tsx +++ b/apps/client/src/pages/auth/register/page.tsx @@ -51,6 +51,8 @@ export const RegisterPage = () => { }); const onSubmit = async (data: FormValues) => { + //email convert to lowecase + data.email = data.email.toLowerCase(); try { await register(data); From a04abd233d5b4c735275a410b57ca7bab91b8fa2 Mon Sep 17 00:00:00 2001 From: Dolly Date: Thu, 4 Apr 2024 13:43:21 +0530 Subject: [PATCH 2/2] fixed email capitalization on backend --- apps/server/src/auth/auth.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/server/src/auth/auth.service.ts b/apps/server/src/auth/auth.service.ts index 605f192ac..ea46887c9 100644 --- a/apps/server/src/auth/auth.service.ts +++ b/apps/server/src/auth/auth.service.ts @@ -46,6 +46,10 @@ export class AuthService { } } + private getLowercase(input : string) : string { + return input.toLowerCase(); + } + generateToken(grantType: "access" | "refresh" | "reset" | "verification", payload?: Payload) { switch (grantType) { case "access": @@ -95,6 +99,7 @@ export class AuthService { async register(registerDto: RegisterDto) { const hashedPassword = await this.hash(registerDto.password); + registerDto.email = this.getLowercase(registerDto.email); try { const user = await this.userService.create({ @@ -122,6 +127,7 @@ export class AuthService { } async authenticate({ identifier, password }: LoginDto) { + identifier = this.getLowercase(identifier); try { const user = await this.userService.findOneByIdentifier(identifier); @@ -143,6 +149,7 @@ export class AuthService { // Password Reset Flows async forgotPassword(email: string) { + email = this.getLowercase(email) const token = this.generateToken("reset"); await this.userService.updateByEmail(email, { @@ -158,6 +165,7 @@ export class AuthService { async updatePassword(email: string, password: string) { const hashedPassword = await this.hash(password); + email = this.getLowercase(email); await this.userService.updateByEmail(email, { secrets: { update: { password: hashedPassword } },