Skip to content

Commit cbd1c3f

Browse files
committed
Check if the email is valid and changed the typing signature so it will not have nullable email field
1 parent 809f75a commit cbd1c3f

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

packages/client/src/AccountsClient.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,17 @@ export class AccountsClient {
269269
}
270270
}
271271

272-
async requestPasswordReset(email?: string): Promise<void> {
273-
if (!email) throw new AccountsError('Email must be provided');
272+
async requestPasswordReset(email: string): Promise<void> {
273+
if (!validators.validateEmail(email)) throw new AccountsError('Valid email must be provided');
274274
try {
275275
await this.transport.sendResetPasswordEmail(email);
276276
} catch (err) {
277277
throw new AccountsError(err.message);
278278
}
279279
}
280280

281-
async requestVerificationEmail(email?: string): Promise<void> {
282-
if (!email) throw new AccountsError('Email must be provided');
281+
async requestVerificationEmail(email: string): Promise<void> {
282+
if (!validators.validateEmail(email)) throw new AccountsError('Valid email must be provided');
283283
try {
284284
await this.transport.sendVerificationEmail(email);
285285
} catch (err) {

packages/client/src/AccountsClient.spec.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ describe('Accounts', () => {
494494
const error = 'something bad';
495495
Accounts.config({}, { sendResetPasswordEmail: () => Promise.reject({ message: error }) });
496496
try {
497-
await Accounts.requestPasswordReset('email');
497+
await Accounts.requestPasswordReset('email@g.co');
498498
throw new Error();
499499
} catch (err) {
500500
expect(err.message).toEqual(error);
@@ -504,9 +504,21 @@ describe('Accounts', () => {
504504
it('should call transport.sendResetPasswordEmail', async () => {
505505
const mock = jest.fn(() => Promise.resolve());
506506
Accounts.config({}, { sendResetPasswordEmail: mock });
507-
await Accounts.requestPasswordReset('email');
507+
await Accounts.requestPasswordReset('email@g.co');
508508
expect(mock.mock.calls.length).toEqual(1);
509-
expect(mock.mock.calls[0][0]).toEqual('email');
509+
expect(mock.mock.calls[0][0]).toEqual('[email protected]');
510+
});
511+
512+
it('should throw if an invalid email is provided', async () => {
513+
const mock = jest.fn();
514+
Accounts.config({}, { sendResetPasswordEmail: mock });
515+
try {
516+
await Accounts.requestPasswordReset('email');
517+
throw new Error();
518+
} catch (err) {
519+
expect(err.message).toEqual('Valid email must be provided');
520+
expect(mock.mock.calls.length).toEqual(0);
521+
}
510522
});
511523
});
512524

@@ -515,7 +527,7 @@ describe('Accounts', () => {
515527
const error = 'something bad';
516528
Accounts.config({}, { sendVerificationEmail: () => Promise.reject({ message: error }) });
517529
try {
518-
await Accounts.requestVerificationEmail('email');
530+
await Accounts.requestVerificationEmail('email@g.co');
519531
throw new Error();
520532
} catch (err) {
521533
expect(err.message).toEqual(error);
@@ -525,9 +537,21 @@ describe('Accounts', () => {
525537
it('should call transport.sendVerificationEmail', async () => {
526538
const mock = jest.fn(() => Promise.resolve());
527539
Accounts.config({}, { sendVerificationEmail: mock });
528-
await Accounts.requestVerificationEmail('email');
540+
await Accounts.requestVerificationEmail('email@g.co');
529541
expect(mock.mock.calls.length).toEqual(1);
530-
expect(mock.mock.calls[0][0]).toEqual('email');
542+
expect(mock.mock.calls[0][0]).toEqual('[email protected]');
543+
});
544+
545+
it('should throw if an invalid email is provided', async () => {
546+
const mock = jest.fn();
547+
Accounts.config({}, { sendVerificationEmail: mock });
548+
try {
549+
await Accounts.requestVerificationEmail('email');
550+
throw new Error();
551+
} catch (err) {
552+
expect(err.message).toEqual('Valid email must be provided');
553+
expect(mock.mock.calls.length).toEqual(0);
554+
}
531555
});
532556
});
533557
});

0 commit comments

Comments
 (0)