Skip to content

Commit

Permalink
Force email lowercase on signup and login.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoBernardino committed Aug 26, 2023
1 parent 8f9e9f2 commit 73cf615
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions public/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ export async function validateLogin(email: string, password: string) {

const passwordKey = await Encryption.getAuthKey(password);

const lowercaseEmail = (email || '').toLocaleLowerCase().trim();

const body: { email: string } = {
email,
email: lowercaseEmail,
};

const response = await fetch('/api/session', { method: 'POST', headers, body: JSON.stringify(body) });
Expand Down Expand Up @@ -235,7 +237,7 @@ export async function validateLogin(email: string, password: string) {
const session: StoredSession = {
sessionId,
userId: user.id,
email,
email: lowercaseEmail,
keyPair,
};

Expand All @@ -261,8 +263,10 @@ export async function createAccount(email: string, password: string) {
const keyPair = await Encryption.generateKeyPair();
const encryptedKeyPair = await Encryption.encrypt(JSON.stringify(keyPair), passwordKey);

const lowercaseEmail = (email || '').toLocaleLowerCase().trim();

const body: { email: string; encrypted_key_pair: string } = {
email,
email: lowercaseEmail,
encrypted_key_pair: encryptedKeyPair,
};

Expand All @@ -276,7 +280,7 @@ export async function createAccount(email: string, password: string) {
const session: StoredSession = {
sessionId,
userId: user.id,
email,
email: lowercaseEmail,
keyPair,
};

Expand Down

0 comments on commit 73cf615

Please sign in to comment.