diff --git a/src/index.js b/src/index.js index 98208c45c96f2f8e954b440bc7eb241d4a3a7aa2..77fcd5a8d161b291842eb94cd9df749014d6edb8 100644 --- a/src/index.js +++ b/src/index.js @@ -93,6 +93,17 @@ class UniID { if (this._clientInfo.platform === 'h5') { this._clientInfo.platform = 'web' } + let fallbackPlatform + switch (this._clientInfo.platform) { + case 'web': + fallbackPlatform = 'h5' + break + case 'app': + fallbackPlatform = 'app-plus' + break + default: + break + } const defaultConfig = { tokenExpiresIn: 7200, tokenExpiresThreshold: 1200, @@ -100,7 +111,12 @@ class UniID { passwordErrorRetryTime: 3600 } const argsRequired = ['tokenSecret', 'tokenExpiresIn'] - const config = Object.assign(defaultConfig, appConfig, appConfig[this._clientInfo.platform]) + const configList = [defaultConfig, appConfig] + if (fallbackPlatform && appConfig[fallbackPlatform]) { + configList.push(appConfig[fallbackPlatform]) + } + configList.push(appConfig[this._clientInfo.platform]) + const config = Object.assign(...configList) argsRequired.forEach((item) => { if (!config || !config[item]) { throw new Error(`Config parameter missing, ${item} is required`)