Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): E-Mail capitalization issue #1820

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/client/src/pages/auth/forgot-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/pages/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/pages/auth/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -122,6 +127,7 @@ export class AuthService {
}

async authenticate({ identifier, password }: LoginDto) {
identifier = this.getLowercase(identifier);
try {
const user = await this.userService.findOneByIdentifier(identifier);

Expand All @@ -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, {
Expand All @@ -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 } },
Expand Down