Options.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const API = require("../../../lib/API")
  2. const { BaseStdResponse } = require("../../../BaseStdResponse")
  3. const { getEnabledUniLoginTypes, getUniLoginRuntimeConfig, VALID_SOCIAL_TYPES } = require('../../../lib/UniLoginClient')
  4. class Options extends API {
  5. constructor() {
  6. super()
  7. this.setPath('/UniLogin/Options')
  8. this.setMethod('GET')
  9. }
  10. async onRequest(req, res) {
  11. try {
  12. const uniConfig = await getUniLoginRuntimeConfig()
  13. const enabledTypes = getEnabledUniLoginTypes(uniConfig)
  14. return res.json({
  15. ...BaseStdResponse.OK,
  16. data: {
  17. configured: true,
  18. enabledTypes,
  19. methods: VALID_SOCIAL_TYPES.map(type => ({
  20. type,
  21. enabled: enabledTypes.includes(type)
  22. }))
  23. }
  24. })
  25. } catch {
  26. return res.json({
  27. ...BaseStdResponse.OK,
  28. data: {
  29. configured: false,
  30. enabledTypes: [],
  31. methods: VALID_SOCIAL_TYPES.map(type => ({
  32. type,
  33. enabled: false
  34. }))
  35. }
  36. })
  37. }
  38. }
  39. }
  40. module.exports.Options = Options