import Vue from 'vue'; import {AxiosError, AxiosResponse} from "axios"; import {isObject} from 'lodash'; export default Vue.component('two-factor-form', { data: function () { return { code: '', }; }, mounted: function () { if ((this.$route.query.token || '').length < 1) { return this.$router.push({ name: 'login' }); } (this.$refs.code as HTMLElement).focus(); }, methods: { submitToken: function () { this.$flash.clear(); window.axios.post(this.route('auth.login-checkpoint'), { confirmation_token: this.$route.query.token, authentication_code: this.$data.code, }) .then((response: AxiosResponse) => { if (!(response.data instanceof Object)) { throw new Error('An error was encountered while processing this login.'); } localStorage.setItem('token', response.data.token); this.$store.dispatch('login'); window.location = response.data.intended; }) .catch((err: AxiosError) => { this.$store.dispatch('logout'); if (!err.response) { return console.error(err); } const response = err.response; if (response.data && isObject(response.data.errors)) { response.data.errors.forEach((error: any) => { this.$flash.error(error.detail); }); this.$router.push({ name: 'login' }); } }); } }, template: `

{{ $t('auth.two_factor.label_help') }}

Back to Login
`, });