Start to integrate licensing with sessions

This commit is contained in:
Rory Powell 2022-03-01 07:16:52 +00:00
parent 011f8a1cc1
commit 8ff9aac4f8
3 changed files with 22 additions and 0 deletions

View File

@ -14,7 +14,10 @@ const populateFromDB = async (userId, tenantId) => {
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) { if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
const account = await accounts.getAccount(user.email) const account = await accounts.getAccount(user.email)
// TODO: Break this out into it's own cache
if (account) { if (account) {
const license = await accounts.getLicense(user.tenantId)
user.license = license
user.account = account user.account = account
user.accountPortalAccess = true user.accountPortalAccess = true
} }

View File

@ -22,3 +22,21 @@ exports.getAccount = async email => {
return json[0] 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
}

View File

@ -170,6 +170,7 @@ exports.getSelf = async ctx => {
// forward session information not found in db // forward session information not found in db
ctx.body.account = ctx.user.account ctx.body.account = ctx.user.account
ctx.body.license = ctx.user.license
ctx.body.budibaseAccess = ctx.user.budibaseAccess ctx.body.budibaseAccess = ctx.user.budibaseAccess
ctx.body.accountPortalAccess = ctx.user.accountPortalAccess ctx.body.accountPortalAccess = ctx.user.accountPortalAccess
ctx.body.csrfToken = ctx.user.csrfToken ctx.body.csrfToken = ctx.user.csrfToken