-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat: Pass event information to verifyUserEmails
#9651
base: alpha
Are you sure you want to change the base?
Changes from all commits
2dbc4d7
6a80811
f1e44c3
517bd62
1a01272
69c03b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const { getAuthForSessionToken } = require('../lib/Auth'); | ||
const Config = require('../lib/Config'); | ||
|
||
describe('verifyUserEmails with Auth Context', () => { | ||
let user; | ||
let config; | ||
|
||
beforeEach(async (done) => { | ||
await reconfigureServer({ | ||
verifyUserEmails: jasmine.createSpy('verifyUserEmails'), | ||
}); | ||
|
||
user = new Parse.User(); | ||
await user.signUp({ | ||
username: 'testuser', | ||
password: 'securepassword', | ||
email: '[email protected]', | ||
}); | ||
|
||
config = Config.get('test'); | ||
done(); | ||
}); | ||
|
||
it('should call verifyUserEmails with correct auth context on signup', async (done) => { | ||
const sessionToken = user.getSessionToken(); | ||
expect(sessionToken).toBeDefined(); | ||
|
||
await getAuthForSessionToken({ | ||
sessionToken, | ||
config, | ||
}); | ||
|
||
expect(config.verifyUserEmails).toHaveBeenCalledWith({ | ||
action: 'signup', | ||
authProvider: 'password', | ||
}); | ||
done(); | ||
}); | ||
|
||
it('should call verifyUserEmails with correct auth context on login', async (done) => { | ||
await Parse.User.logIn('testuser', 'securepassword'); | ||
|
||
expect(config.verifyUserEmails).toHaveBeenCalledWith({ | ||
action: 'login', | ||
authProvider: 'password', | ||
}); | ||
done(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
}); | ||
|
||
it('should call verifyUserEmails with correct provider for social login', async (done) => { | ||
const socialAuthData = { | ||
id: '1234567890', | ||
access_token: 'mockAccessToken', | ||
}; | ||
|
||
await Parse.User.logInWith('facebook', { authData: socialAuthData }); | ||
|
||
expect(config.verifyUserEmails).toHaveBeenCalledWith({ | ||
action: 'login', | ||
authProvider: 'facebook', | ||
}); | ||
done(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,9 @@ var RestQuery = require('../RestQuery'); | |
var Auth = require('../Auth'); | ||
|
||
export class UserController extends AdaptableController { | ||
constructor(adapter, appId, options = {}) { | ||
constructor(adapter, appId, options = {}, authContext = {}) { | ||
super(adapter, appId, options); | ||
this.authContext = authContext; | ||
} | ||
|
||
get config() { | ||
|
@@ -38,16 +39,21 @@ export class UserController extends AdaptableController { | |
async setEmailVerifyToken(user, req, storage = {}) { | ||
const shouldSendEmail = | ||
this.shouldVerifyEmails === true || | ||
(typeof this.shouldVerifyEmails === 'function' && | ||
(await Promise.resolve(this.shouldVerifyEmails(req))) === true); | ||
(typeof this.shouldVerifyEmails === "function" && | ||
(await Promise.resolve( | ||
this.shouldVerifyEmails({ | ||
user: Parse.Object.fromJSON({ className: "_User", ...user }), | ||
authContext: this.authContext | ||
}) | ||
)) === true); | ||
if (!shouldSendEmail) { | ||
return false; | ||
} | ||
storage.sendVerificationEmail = true; | ||
user._email_verify_token = randomString(25); | ||
if ( | ||
!storage.fieldsChangedByTrigger || | ||
!storage.fieldsChangedByTrigger.includes('emailVerified') | ||
!storage.fieldsChangedByTrigger.includes("emailVerified") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert, we use single quot marks |
||
) { | ||
user.emailVerified = false; | ||
} | ||
|
@@ -60,6 +66,7 @@ export class UserController extends AdaptableController { | |
return true; | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please review formatting in general, like this added empty line. |
||
async verifyEmail(token) { | ||
if (!this.shouldVerifyEmails) { | ||
// Trying to verify email when not enabled | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we already have a spec file for email verification? If so, please move the tests to there instead of creating a new file.