mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
prevent sub accidentally also being applied to other account
This commit is contained in:
parent
57fb7ca6f2
commit
c29049146d
1 changed files with 6 additions and 2 deletions
|
|
@ -127,14 +127,18 @@ api.subscribe = async function subscribe (user, receipt, headers, nextPaymentPro
|
|||
}
|
||||
}
|
||||
const existingUsers = await User.find({
|
||||
'purchased.plan.customerId': purchase.originalTransactionId,
|
||||
$or: [
|
||||
{ 'purchased.plan.customerId': purchase.originalTransactionId },
|
||||
{ 'purchased.plan.customerId': purchase.transactionId },
|
||||
]
|
||||
|
||||
}).exec();
|
||||
if (existingUsers.length > 0) {
|
||||
if (purchase.originalTransactionId === purchase.transactionId) {
|
||||
throw new NotAuthorized(this.constants.RESPONSE_ALREADY_USED);
|
||||
}
|
||||
for (const existingUser of existingUsers) {
|
||||
if (existingUser._id !== user._id && !existingUser.purchased.plan.dateTerminated) {
|
||||
if (existingUser._id !== user._id) {
|
||||
throw new NotAuthorized(this.constants.RESPONSE_ALREADY_USED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue