1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

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) {
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
}

View file

@ -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
}

View file

@ -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