<script>
const api = require('./api')
const { jwt } = require('./security')
export default {
  data() {
    return {
      model: {
        confirmKey: null
      }
    }
  },
  methods: {
    async submit() {
      const result = await api.post('confirm', {
        email: this.$route.params.email,
        ...this.model
      })
      console.log(result)
      if (result.error) {
        this.error = result.error
      } else {
        jwt.token = result.token
        this.$router.push('/dashboard')
      }
    }
  }
}
</script>
<template>
  <div>
    <h1>Confirm your email address</h1>
    <p>
      We emailed you a confirmation code. Please enter it here to confirm your email address.
    </p>
    <p>
      <em>I can almost guarantee this email will be in your spam folder, but don't worry. Your email address is only used for signing in, and resetting your password.</em>
    </p>
    <v-text-field v-model="model.confirmKey" label="Enter your confirmation key" placeholder="###-###" />
    <v-btn @click="submit">Confirm Email</v-btn>
    <v-alert :value="true" v-if="error" type="error" dismissible>{{error}}</v-alert>
  </div>
</template>
