mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-26 10:42:52 +01:00
prevent sub accidentally also being applied to other account
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user