diff --git a/packages/backend-core/src/cache/user.js b/packages/backend-core/src/cache/user.js index 60a2d341a8..e409532a5c 100644 --- a/packages/backend-core/src/cache/user.js +++ b/packages/backend-core/src/cache/user.js @@ -14,7 +14,10 @@ const populateFromDB = async (userId, tenantId) => { if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) { const account = await accounts.getAccount(user.email) + // TODO: Break this out into it's own cache if (account) { + const license = await accounts.getLicense(user.tenantId) + user.license = license user.account = account user.accountPortalAccess = true } diff --git a/packages/backend-core/src/cloud/accounts.js b/packages/backend-core/src/cloud/accounts.js index b2e8817ad6..87bb4dcf52 100644 --- a/packages/backend-core/src/cloud/accounts.js +++ b/packages/backend-core/src/cloud/accounts.js @@ -22,3 +22,21 @@ exports.getAccount = async email => { return json[0] } + +// TODO: Replace with licensing key +exports.getLicense = async tenantId => { + const response = await api.get(`/api/license/${tenantId}`, { + headers: { + [Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, + }, + }) + + if (response.status !== 200) { + const text = await response.text() + console.error("Error getting license: ", text) + throw new Error(`Error getting license for tenant ${tenantId}`) + } + + const json = await response.json() + return json +} diff --git a/packages/worker/src/api/controllers/global/users.js b/packages/worker/src/api/controllers/global/users.js index f2d89e103a..b2db340f9a 100644 --- a/packages/worker/src/api/controllers/global/users.js +++ b/packages/worker/src/api/controllers/global/users.js @@ -170,6 +170,7 @@ exports.getSelf = async ctx => { // forward session information not found in db ctx.body.account = ctx.user.account + ctx.body.license = ctx.user.license ctx.body.budibaseAccess = ctx.user.budibaseAccess ctx.body.accountPortalAccess = ctx.user.accountPortalAccess ctx.body.csrfToken = ctx.user.csrfToken