Skip to content

Commit

Permalink
feat: Add Parse.User as function parameter to Parse Server options …
Browse files Browse the repository at this point in the history
…`verifyUserEmails`, `preventLoginWithUnverifiedEmail` on login (#8850)
  • Loading branch information
mtrezza authored Dec 27, 2023
1 parent 19fc546 commit 972f630
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/ValidationAndPasswordsReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,41 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
expect(loginRes.message).toEqual('User email is not verified.');
});

it('provides function arguments in verifyUserEmails on login', async () => {
const user = new Parse.User();
user.setUsername('user');
user.setPassword('pass');
user.set('email', '[email protected]');
await user.signUp();

const verifyUserEmails = {
method: async (params) => {
expect(params.object).toBeInstanceOf(Parse.User);
expect(params.ip).toBeDefined();
expect(params.master).toBeDefined();
expect(params.installationId).toBeDefined();
return true;
},
};
const verifyUserEmailsSpy = spyOn(verifyUserEmails, 'method').and.callThrough();
await reconfigureServer({
appName: 'test',
publicServerURL: 'http://localhost:1337/1',
verifyUserEmails: verifyUserEmails.method,
preventLoginWithUnverifiedEmail: verifyUserEmails.method,
preventSignupWithUnverifiedEmail: true,
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: '[email protected]',
apiKey: 'k',
domain: 'd',
}),
});

const res = await Parse.User.logIn('user', 'pass').catch(e => e);
expect(res.code).toBe(205);
expect(verifyUserEmailsSpy).toHaveBeenCalledTimes(2);
});

it('allows user to login only after user clicks on the link to confirm email address if preventLoginWithUnverifiedEmail is set to true', async () => {
let sendEmailOptions;
const emailAdapter = {
Expand Down
1 change: 1 addition & 0 deletions src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class UsersRouter extends ClassesRouter {
master: req.auth.isMaster,
ip: req.config.ip,
installationId: req.auth.installationId,
object: Parse.User.fromJSON(Object.assign({ className: '_User' }, user)),
};
// Get verification conditions which can be booleans or functions; the purpose of this async/await
// structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the
Expand Down

0 comments on commit 972f630

Please sign in to comment.