2021-09-19 17:30:37 +02:00
|
|
|
// SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
import { createStore } from 'vuex'
|
|
|
|
|
2021-09-21 23:56:17 +02:00
|
|
|
import search from './search'
|
|
|
|
|
2021-09-19 17:30:37 +02:00
|
|
|
const localStorageKeys = {
|
|
|
|
currentUserId: 'ki_current_user_id',
|
|
|
|
token: 'ki_token',
|
|
|
|
}
|
|
|
|
|
|
|
|
export default createStore({
|
2021-09-21 23:56:17 +02:00
|
|
|
modules: {
|
|
|
|
search,
|
|
|
|
},
|
2021-09-19 17:30:37 +02:00
|
|
|
state() {
|
|
|
|
return {
|
|
|
|
currentUserId: JSON.parse(localStorage.getItem(localStorageKeys.currentUserId)),
|
|
|
|
token: JSON.parse(localStorage.getItem(localStorageKeys.token)),
|
|
|
|
currentProfile: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
clearCurrentUserId(state) {
|
|
|
|
state.currentUserId = null
|
|
|
|
localStorage.removeItem(localStorageKeys.currentUserId)
|
|
|
|
},
|
|
|
|
setCurrentUserId(state, currentUserId) {
|
|
|
|
state.currentUserId = currentUserId
|
|
|
|
localStorage.setItem(
|
|
|
|
localStorageKeys.currentUserId,
|
|
|
|
JSON.stringify(currentUserId)
|
|
|
|
)
|
|
|
|
},
|
|
|
|
clearToken(state) {
|
|
|
|
state.token = null
|
|
|
|
localStorage.removeItem(localStorageKeys.token)
|
|
|
|
},
|
|
|
|
setToken(state, token) {
|
|
|
|
state.token = token
|
|
|
|
localStorage.setItem(localStorageKeys.token, JSON.stringify(token))
|
|
|
|
},
|
|
|
|
setCurrentProfile(state, profile) {
|
|
|
|
state.currentProfile = profile
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
clear(context) {
|
|
|
|
context.commit('clearCurrentUserId')
|
|
|
|
context.commit('clearToken')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|