Skip to content

Commit 0c99851

Browse files
committed
fix(discord-bot): resolve getUserLicenses via dashboard link, not Discord ID as email
1 parent 7a0632e commit 0c99851

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/client/LicenseChainClient.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const axios = require('axios');
66
const crypto = require('crypto');
77
const { normalizeAxiosError, normalizeVerifyPayload } = require('./licensechainApiNormalize');
8+
const { getLinkedUser } = require('./DashboardClient');
89

910
class LicenseChainClient {
1011
constructor(config) {
@@ -79,6 +80,12 @@ class LicenseChainClient {
7980
*/
8081
async getUserLicenses(userId) {
8182
try {
83+
const linked = await getLinkedUser(userId);
84+
const linkedEmail = (linked?.email || '').trim().toLowerCase();
85+
if (!linkedEmail) {
86+
throw new Error('DISCORD_ACCOUNT_NOT_LINKED');
87+
}
88+
8289
// Get all app licenses and filter by user
8390
const appName = process.env.LICENSECHAIN_APP_NAME;
8491
if (!appName) {
@@ -98,10 +105,11 @@ class LicenseChainClient {
98105
const licensesData = await this.getAppLicenses(appId);
99106
const allLicenses = licensesData?.licenses || licensesData || [];
100107

101-
// Filter licenses by userId (email or issuedTo matching)
102-
// Note: This is a simplified filter - adjust based on your data structure
108+
// Scope licenses by linked dashboard email to avoid discord-id/email drift.
103109
return allLicenses.filter(license => {
104-
return license.issuedEmail === userId || license.issuedTo === userId || license.email === userId;
110+
const issuedEmail = (license?.issuedEmail || '').trim().toLowerCase();
111+
const email = (license?.email || '').trim().toLowerCase();
112+
return issuedEmail === linkedEmail || email === linkedEmail;
105113
});
106114
} catch (error) {
107115
throw new Error(`Failed to get user licenses: ${error.response?.data?.message || error.message}`);

src/commands/license.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ module.exports = {
237237
}));
238238
}
239239
} catch (apiError) {
240+
if (String(apiError.message || '').includes('DISCORD_ACCOUNT_NOT_LINKED')) {
241+
const embed = new EmbedBuilder()
242+
.setColor('#ffaa00')
243+
.setTitle('🔗 Account Link Required')
244+
.setDescription('Link your Discord account in the LicenseChain Dashboard, then run `/license list` again.')
245+
.setTimestamp();
246+
await interaction.editReply({ embeds: [embed] });
247+
return;
248+
}
240249
console.warn('Could not fetch licenses from API:', apiError.message);
241250
}
242251
}

0 commit comments

Comments
 (0)