Skip to content

Commit 46ed51f

Browse files
committed
fix: remove address extensions
1 parent 9c2676d commit 46ed51f

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

users/emailConfirmationTokensRepo.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@aws-sdk/client-dynamodb'
66
import { marshall } from '@aws-sdk/util-dynamodb'
77
import { generateCode } from '@hello.nrfcloud.com/proto/fingerprint'
8+
import { normalizeEmail } from './normalizeEmail.js'
89

910
export const emailConfirmationTokensRepo = ({
1011
db,
@@ -57,7 +58,7 @@ export const emailConfirmationTokensRepo = ({
5758
await db.send(
5859
new UpdateItemCommand({
5960
TableName,
60-
Key: marshall({ email: normalize(email) }),
61+
Key: marshall({ email: normalizeEmail(email) }),
6162
UpdateExpression:
6263
'SET #confirmationToken = :confirmationToken, #ttl = :ttl, #rerequestAfter = :rerequestAfter',
6364
ConditionExpression:
@@ -101,7 +102,7 @@ export const emailConfirmationTokensRepo = ({
101102
const item = await db.send(
102103
new GetItemCommand({
103104
TableName,
104-
Key: marshall({ email: normalize(email) }),
105+
Key: marshall({ email: normalizeEmail(email) }),
105106
}),
106107
)
107108
if (item.Item?.confirmationToken?.S !== token) {
@@ -122,5 +123,3 @@ export const emailConfirmationTokensRepo = ({
122123
},
123124
}
124125
}
125-
126-
const normalize = (email: string) => email.trim().toLowerCase()

users/normalizeEmail.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import assert from 'node:assert/strict'
2+
import { describe, it } from 'node:test'
3+
import { normalizeEmail } from './normalizeEmail.js'
4+
5+
void describe('normalizeEmail()', () => {
6+
void it('lower-case an email', () => {
7+
assert.equal(normalizeEmail('[email protected]'), '[email protected]')
8+
})
9+
10+
void it('should remove extensions', () => {
11+
assert.equal(
12+
normalizeEmail('[email protected]'),
13+
14+
)
15+
})
16+
})

users/normalizeEmail.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const normalizeEmail = (email: string): string => {
2+
const normalized = email.trim().toLowerCase()
3+
const [user, domain] = normalized.split('@') as [string, string]
4+
return `${user.split('+')[0]}@${domain}`
5+
}

0 commit comments

Comments
 (0)