akkoma-fe/src/components/mfa_form/totp_form.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

import mfaApi from '../../services/new_api/mfa.js'
import { mapState, mapGetters, mapActions, mapMutations } from 'vuex'
2020-10-20 18:18:23 +00:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faTimes
} from '@fortawesome/free-solid-svg-icons'
library.add(
faTimes
)
export default {
data: () => ({
code: null,
error: false
}),
computed: {
...mapGetters({
authSettings: 'authFlow/settings'
}),
2019-12-12 05:42:21 +00:00
...mapState({
instance: 'instance',
oauth: 'oauth'
})
},
methods: {
...mapMutations('authFlow', ['requireRecovery', 'abortMFA']),
...mapActions({ login: 'authFlow/login' }),
clearError () { this.error = false },
submit () {
2019-12-12 05:42:21 +00:00
const { clientId, clientSecret } = this.oauth
const data = {
2019-12-12 05:42:21 +00:00
clientId,
clientSecret,
instance: this.instance.server,
mfaToken: this.authSettings.mfa_token,
code: this.code
}
mfaApi.verifyOTPCode(data).then((result) => {
if (result.error) {
this.error = result.error
this.code = null
return
}
this.login(result).then(() => {
2019-07-05 07:02:14 +00:00
this.$router.push({ name: 'friends' })
})
})
}
}
}