<template>
  <v-content>
    <v-container>
      <Header>
        <LoginForm :session="session" />
        <RegisterForm />
      </Header>

      <p class="subheading font-weight-regular">
        App under development, please don't submit any valuable data!
      </p>
    </v-container>
  </v-content>
</template>

<script>
import * as Cookies from 'js-cookie'
import axios from '@/plugins/axios'

import Header from '@/components/Header.vue'
import LoginForm from '@/components/forms/Login.vue'
import RegisterForm from '@/components/forms/Register.vue'

export default {
  name: 'Home',

  components: {
    Header,
    LoginForm,
    RegisterForm
  },

  computed: {
    session: () => Cookies.get('session')
  },

  mounted() {
    this.$nextTick(() => {
      if (this.session) {
        axios
          .post('/user/login', {
            session: this.session
          })
          .then(response => {
            if (response.data.success) {
              this.$router.push({ name: 'deckcp' })
            }
          })
      }
    })
  }
}
</script>
