get-supported-login-type.js 1.5 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
function isMobileCodeSupported () {
  const config = this.config
  return !!(config.service && config.service.sms && config.service.sms.smsKey)
}

function isUniverifySupport () {
  const config = this.config
  return !!(config.service && config.service.univerify && config.service.univerify.apiKey)
}

function isWeixinSupported () {
  this.configUtils.getOauthConfig({
    provider: 'weixin'
  })
  return true
}

function isQQSupported () {
  this.configUtils.getOauthConfig({
    provider: 'qq'
  })
  return true
}

function isAppleSupported () {
  this.configUtils.getOauthConfig({
    provider: 'apple'
  })
  return true
}

function isAlipaySupported () {
  this.configUtils.getOauthConfig({
    provider: 'alipay'
  })
  return true
}

const loginTypeTester = {
  'mobile-code': isMobileCodeSupported,
  univerify: isUniverifySupport,
  weixin: isWeixinSupported,
  qq: isQQSupported,
  apple: isAppleSupported,
  alipay: isAlipaySupported
}

/**
 * 获取支持的登录方式
 * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
 * @returns
 */
module.exports = async function () {
  const supportedLoginType = [
    'username-password',
    'mobile-password',
    'email-password'
  ]
  for (const type in loginTypeTester) {
    try {
      if (loginTypeTester[type].call(this)) {
        supportedLoginType.push(type)
      }
    } catch (error) { }
  }
  return {
    errCode: 0,
    errMsg: '',
    supportedLoginType
  }
}