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

      this._lastTime = e.timeStamp;

      if (!this.auth) {
        return this.$emit('click');
      }

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

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