<script>
const api = require('./api')
const { jwt } = require('./security')
export default {
  data() {
    return {
      error: null,
      model: {
        email: null,
        password: null
      }
    }
  },
  methods: {
    async login() {
      const result = await api.post('login', this.model)
      if (result.error) {
        this.error = result.error
      } else {
        jwt.token = result.token
        this.$router.push('/dashboard')
      }
    }
  }
}
</script>
<template>
  <v-form>
    <v-text-field v-model="model.email" label="Email" />
    <v-text-field v-model="model.password" type="password" label="Password" />
    <v-btn @click="login">Sign in</v-btn>
    <v-alert type="warning" dismissible :value="error">{{error}}</v-alert>
  </v-form>
</template>
