Skip to content

Commit 972f630

Browse files
authored
feat: Add Parse.User as function parameter to Parse Server options verifyUserEmails, preventLoginWithUnverifiedEmail on login (#8850)
1 parent 19fc546 commit 972f630

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

spec/ValidationAndPasswordsReset.spec.js

+35
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,41 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
267267
expect(loginRes.message).toEqual('User email is not verified.');
268268
});
269269

270+
it('provides function arguments in verifyUserEmails on login', async () => {
271+
const user = new Parse.User();
272+
user.setUsername('user');
273+
user.setPassword('pass');
274+
user.set('email', '[email protected]');
275+
await user.signUp();
276+
277+
const verifyUserEmails = {
278+
method: async (params) => {
279+
expect(params.object).toBeInstanceOf(Parse.User);
280+
expect(params.ip).toBeDefined();
281+
expect(params.master).toBeDefined();
282+
expect(params.installationId).toBeDefined();
283+
return true;
284+
},
285+
};
286+
const verifyUserEmailsSpy = spyOn(verifyUserEmails, 'method').and.callThrough();
287+
await reconfigureServer({
288+
appName: 'test',
289+
publicServerURL: 'http://localhost:1337/1',
290+
verifyUserEmails: verifyUserEmails.method,
291+
preventLoginWithUnverifiedEmail: verifyUserEmails.method,
292+
preventSignupWithUnverifiedEmail: true,
293+
emailAdapter: MockEmailAdapterWithOptions({
294+
fromAddress: '[email protected]',
295+
apiKey: 'k',
296+
domain: 'd',
297+
}),
298+
});
299+
300+
const res = await Parse.User.logIn('user', 'pass').catch(e => e);
301+
expect(res.code).toBe(205);
302+
expect(verifyUserEmailsSpy).toHaveBeenCalledTimes(2);
303+
});
304+
270305
it('allows user to login only after user clicks on the link to confirm email address if preventLoginWithUnverifiedEmail is set to true', async () => {
271306
let sendEmailOptions;
272307
const emailAdapter = {

src/Routers/UsersRouter.js

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class UsersRouter extends ClassesRouter {
142142
master: req.auth.isMaster,
143143
ip: req.config.ip,
144144
installationId: req.auth.installationId,
145+
object: Parse.User.fromJSON(Object.assign({ className: '_User' }, user)),
145146
};
146147
// Get verification conditions which can be booleans or functions; the purpose of this async/await
147148
// structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the

0 commit comments

Comments
 (0)