Merge pull request #215 from gradido/logout-API-from-component

refactor: Remove loginAPI Call from Store
This commit is contained in:
Moriz Wahl 2021-04-22 11:05:25 +02:00 committed by GitHub
commit 009714a0b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 44 deletions

View File

@ -102,8 +102,7 @@ export default {
this.$sidebar.displaySidebar(true)
},
logout() {
this.$store.dispatch('logout')
this.$router.push('/login')
this.$emit('logout')
},
},
}

View File

@ -1,7 +1,6 @@
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import loginAPI from '../apis/loginAPI'
import communityAPI from '../apis/communityAPI'
import createPersistedState from 'vuex-persistedstate'
@ -49,23 +48,19 @@ export const store = new Vuex.Store({
},
},
actions: {
login: async ({ dispatch, commit }, data) => {
login: ({ dispatch, commit }, data) => {
commit('session_id', data.session_id)
commit('email', data.email)
},
passwordReset: async (data) => {},
schoepfen: async (data) => {
passwordReset: (data) => {},
schoepfen: (data) => {
// http://localhost/transaction-creations/ajaxCreate
},
createUser: async ({ commit, dispatch }, data) => {
createUser: ({ commit, dispatch }, data) => {
commit('session_id', data.session_id)
commit('email', data.email)
},
logout: async ({ commit, state }) => {
if (state.session_id) {
const result = await loginAPI.logout(state.session_id)
// The result can be error, but thats ok with us
}
logout: ({ commit, state }) => {
commit('session_id', null)
commit('email', null)
sessionStorage.clear()

View File

@ -1,7 +1,7 @@
<template>
<div class="wrapper">
<notifications></notifications>
<side-bar>
<side-bar @logout="logout">
<template slot="links">
<b-nav-item href="#!" to="/overview">
<b-nav-text class="p-0 text-lg text-muted">{{ $t('send') }}</b-nav-text>
@ -36,6 +36,7 @@
<script>
import PerfectScrollbar from 'perfect-scrollbar'
import 'perfect-scrollbar/css/perfect-scrollbar.css'
import loginAPI from '../../apis/loginAPI'
function hasElement(className) {
return document.getElementsByClassName(className).length > 0
@ -71,6 +72,12 @@ export default {
initScrollbar('sidenav')
}
},
async logout() {
const result = await loginAPI.logout(this.$store.state.session_id)
// do we have to check success?
this.$store.dispatch('logout')
this.$router.push('/login')
},
},
mounted() {
this.initScrollbar()

View File

@ -37,37 +37,6 @@ export default {
props: {
type: {
type: String,
default: 'default', // default|light
description: 'Look of the dashboard navbar. Default (Green) or light (gray)',
},
},
computed: {
routeName() {
const { name } = this.$route
return this.capitalizeFirstLetter(name)
},
},
data() {
return {
activeNotifications: false,
showMenu: false,
searchModalVisible: false,
searchQuery: '',
}
},
methods: {
capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1)
},
toggleNotificationDropDown() {
this.activeNotifications = !this.activeNotifications
},
closeDropDown() {
this.activeNotifications = false
},
logout() {
this.$store.dispatch('logout')
this.$router.push('/login')
},
},
}