<template>
  <div class="page-authentication">
    <!-- 自动登录页面 -->
  </div>
</template>

<script>
export default {
  name: 'authentication',
  created () {
    this.login();
  },
  methods: {
    login() {
      this.$post('/login/index').then(this.loginSuccess).catch(this.loginFail)
    },
    loginSuccess({data}) {
      this.$store.commit('setUserData', data);
      this.$router.replace({
        path: this.redirect,
      });
    },
    loginFail(error) {
      this.$message.error(error.message || '请登录');
      this.$router.replace({
        path: '/login',
        query: {
          redirect: this.redirect,
        }
      });
    }
  },
  computed: {
    isLogin() {
      return this.$store.state.isLogin
    }
  },
  data() {
    return {
      redirect: this.$route.query.redirect,
      loading: true,
    }
  }
}
</script>
