overleaf/services/web/app/src/Features/User/UserPrimaryEmailCheckHandler.js
Mathias Jakobsen 38cc3394e3 Merge pull request #10793 from overleaf/mj-split-test-cleanup
Split test clean-up

GitOrigin-RevId: 7dd6178487022cbefcbc85797dacc3f3fbfa17e2
2022-12-21 09:04:04 +00:00

33 lines
688 B
JavaScript

const Settings = require('@overleaf/settings')
function requiresPrimaryEmailCheck({
email,
emails,
lastPrimaryEmailCheck,
signUpDate,
}) {
const hasExpired = date => {
if (!date) {
return true
}
return Date.now() - date.getTime() > Settings.primary_email_check_expiration
}
const primaryEmailConfirmedAt = emails.find(
emailEntry => emailEntry.email === email
).confirmedAt
if (primaryEmailConfirmedAt && !hasExpired(primaryEmailConfirmedAt)) {
return false
}
if (lastPrimaryEmailCheck) {
return hasExpired(lastPrimaryEmailCheck)
} else {
return hasExpired(signUpDate)
}
}
module.exports = {
requiresPrimaryEmailCheck,
}