auth-component.js 751 Bytes
export default {
  name: 'AuthComponent',
  props: {
    tag: String,
    requiredAuth: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    async onClick(e) {
      if (e.timeStamp - this._lastTime < 800) {
        return;
      }

      this._lastTime = e.timeStamp;

      if (this.requiredAuth) {
        const user = await this.$sdk.getUser();

        if (user && user.uid) {
          this.$emit('click', {uid: user.uid});
        } else {
          this.$emit('cancel');
          this.$sdk.goLogin();
        }
      } else {
        return this.$emit('click');
      }
    }
  },
  render(h) {
    return h(this.tag || 'div', {
      on: {
        click: this.onClick.bind(this)
      }
    }, this.$slots.default);
  }
};