zhaoyingbo 6e65581bbf
All checks were successful
Egg CI/CD / build-image (push) Successful in 32s
Egg CI/CD / deploy (push) Successful in 37s
feat: 接入lint 和 husky
2024-07-25 01:48:22 +00:00

43 lines
968 B
TypeScript

import appInfo from "../appInfo"
import pbClient from "../pbClient"
const tokenCache = {} as Record<string, string>
/**
* 更新租户的token
* @param {string} id 记录id
* @param {string} appName 租户名称
* @param {string} value 新的token
*/
const update = async (id: string, appName: string, value: string) => {
try {
await pbClient
.collection("app_info")
.update(id, { tenant_access_token: value })
} catch {
/* empty */
}
tokenCache[appName] = value
console.log(`reset ${appName} access token success`, value)
}
/**
* 获取租户的token
* @param {string} appName 租户名称
* @returns {string} 租户的token
*/
const get = async (appName: string) => {
if (tokenCache[appName]) return tokenCache[appName]
const config = await appInfo.getVal(appName, "tenant_access_token")
tokenCache[appName] = config
return config
}
const tenantAccessToken = {
get,
update,
}
export default tenantAccessToken