| const { getUserPluginAuthValue } = require('~/server/services/PluginService'); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| const loadAuthValues = async ({ userId, authFields, optional, throwError = true }) => { |
| let authValues = {}; |
|
|
| |
| |
| |
| |
| |
| const findAuthValue = async (fields) => { |
| for (const field of fields) { |
| let value = process.env[field]; |
| if (value) { |
| return { authField: field, authValue: value }; |
| } |
| try { |
| value = await getUserPluginAuthValue(userId, field, throwError); |
| } catch (err) { |
| if (optional && optional.has(field)) { |
| return { authField: field, authValue: undefined }; |
| } |
| if (field === fields[fields.length - 1] && !value) { |
| throw err; |
| } |
| } |
| if (value) { |
| return { authField: field, authValue: value }; |
| } |
| } |
| return null; |
| }; |
|
|
| for (let authField of authFields) { |
| const fields = authField.split('||'); |
| const result = await findAuthValue(fields); |
| if (result) { |
| authValues[result.authField] = result.authValue; |
| } |
| } |
|
|
| return authValues; |
| }; |
|
|
| module.exports = { |
| loadAuthValues, |
| }; |
|
|