Skip to content

Stop requiring verifyUserEmails for password reset functionality #2166

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

Merged
Merged
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
7 changes: 4 additions & 3 deletions spec/ValidationAndPasswordsReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
});
});

it_exclude_dbs(['postgres'])('fails if you include an emailAdapter, set verifyUserEmails to false, dont set a publicServerURL, and try to send a password reset email (regression test for #1649)', done => {
it_exclude_dbs(['postgres'])('fails if you include an emailAdapter, set a publicServerURL, but have no appName and send a password reset email', done => {
reconfigureServer({
appName: 'unused',
verifyUserEmails: false,
appName: undefined,
publicServerURL: 'http://localhost:1337/1',
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: 'parse@example.com',
apiKey: 'k',
Expand Down Expand Up @@ -278,6 +278,7 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
}
reconfigureServer({
appName: 'unused',
publicServerURL: 'http://localhost:1337/1',
verifyUserEmails: false,
emailAdapter: emailAdapter,
})
Expand Down
18 changes: 9 additions & 9 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ export class Config {

static validate({
verifyUserEmails,
userController,
appName,
publicServerURL,
revokeSessionOnPasswordReset,
expireInactiveSessions,
sessionLength,
}) {
this.validateEmailConfiguration({
verifyUserEmails: verifyUserEmails,
appName: appName,
publicServerURL: publicServerURL
})
const emailAdapter = userController.adapter;
if (verifyUserEmails) {
this.validateEmailConfiguration({emailAdapter, appName, publicServerURL});
}

if (typeof revokeSessionOnPasswordReset !== 'boolean') {
throw 'revokeSessionOnPasswordReset must be a boolean value';
Expand All @@ -81,13 +81,13 @@ export class Config {
this.validateSessionConfiguration(sessionLength, expireInactiveSessions);
}

static validateEmailConfiguration({verifyUserEmails, appName, publicServerURL}) {
if (verifyUserEmails) {
static validateEmailConfiguration({emailAdapter, appName, publicServerURL}) {
if (emailAdapter) {
if (typeof appName !== 'string') {
throw 'An app name is required when using email verification.';
throw 'An app name is required for e-mail verification and password resets.';
}
if (typeof publicServerURL !== 'string') {
throw 'A public server url is required when using email verification.';
throw 'A public server url is required for e-mail verification and password resets.';
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class UsersRouter extends ClassesRouter {
handleResetRequest(req) {
try {
Config.validateEmailConfiguration({
verifyUserEmails: true, //A bit of a hack, as this isn't the intended purpose of this parameter
emailAdapter: req.config.userController,
appName: req.config.appName,
publicServerURL: req.config.publicServerURL,
});
Expand Down