Welcome to mirror list, hosted at ThFree Co, Russian Federation.

store.js « src - github.com/nextcloud/twofactor_u2f.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 25907769c74d597f0d675bdd0558beff6d4a0a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Vue from 'vue'
import Vuex from 'vuex'

import {removeRegistration} from './services/RegistrationService'

Vue.use(Vuex)

export const mutations = {
	addDevice (state, device) {
		state.devices.push(device)
		state.devices.sort((d1, d2) => d1.name.localeCompare(d2.name))
	},

	removeDevice (state, id) {
		state.devices = state.devices.filter(device => device.id !== id)
	}
}

export const actions = {
	removeDevice ({state, commit}, id) {
		const device = state.devices[id]

		commit('removeDevice', id)

		removeRegistration(id)
			.catch(err => {
				// Rollback
				commit('addDevice', device)

				throw err
			})
	}
}

export const getters = {}

export default new Vuex.Store({
	strict: process.env.NODE_ENV !== 'production',
	state: {
		devices: []
	},
	getters,
	mutations,
	actions
})