Skip to content
Snippets Groups Projects
Commit 66ee3f37 authored by Martin Weise's avatar Martin Weise
Browse files

Merge branch 'ui-february' into '122-test-amqp'

Persist token in localStorage

See merge request !38

Former-commit-id: 876c62a7
parents 8c7af071 e92a1ac2
Branches
Tags
1 merge request!42Fixed the query service tests
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
to="/signup"> to="/signup">
<v-icon left>mdi-account-plus</v-icon> Signup <v-icon left>mdi-account-plus</v-icon> Signup
</v-btn> </v-btn>
{{ username }}
<v-menu bottom offset-y left> <v-menu bottom offset-y left>
<template v-slot:activator="{ on, attrs }"> <template v-slot:activator="{ on, attrs }">
<v-btn <v-btn
...@@ -62,6 +63,10 @@ ...@@ -62,6 +63,10 @@
@click="switchTheme()"> @click="switchTheme()">
{{ nextTheme }} Theme {{ nextTheme }} Theme
</v-list-item> </v-list-item>
<v-list-item
@click="logout">
Logout
</v-list-item>
</v-list> </v-list>
</v-menu> </v-menu>
</v-app-bar> </v-app-bar>
...@@ -150,6 +155,9 @@ export default { ...@@ -150,6 +155,9 @@ export default {
token () { token () {
return this.$store.state.token return this.$store.state.token
}, },
username () {
return this.$store.state.user && this.$store.state.user.username
},
nextTheme () { nextTheme () {
return this.$vuetify.theme.dark ? 'Light' : 'Dark' return this.$vuetify.theme.dark ? 'Light' : 'Dark'
}, },
...@@ -178,6 +186,12 @@ export default { ...@@ -178,6 +186,12 @@ export default {
switchTheme () { switchTheme () {
this.$vuetify.theme.dark = !this.$vuetify.theme.dark this.$vuetify.theme.dark = !this.$vuetify.theme.dark
}, },
logout () {
this.$store.commit('SET_TOKEN', null)
this.$store.commit('SET_USER', null)
this.$toast.success('Logged out')
this.$router.push('/container')
},
async loadDB () { async loadDB () {
if (this.$route.params.db_id && !this.db) { if (this.$route.params.db_id && !this.db) {
try { try {
......
...@@ -55,7 +55,8 @@ export default { ...@@ -55,7 +55,8 @@ export default {
plugins: [ plugins: [
{ src: '~/plugins/toast', ssr: false }, { src: '~/plugins/toast', ssr: false },
{ src: '~/plugins/vendors', ssr: false }, { src: '~/plugins/vendors', ssr: false },
{ src: '~/plugins/axios' } { src: '~/plugins/axios' },
{ src: '~/plugins/vuex-persist.js', mode: 'client' }
], ],
// Auto import components (https://go.nuxtjs.dev/config-components) // Auto import components (https://go.nuxtjs.dev/config-components)
......
...@@ -86,6 +86,9 @@ export default { ...@@ -86,6 +86,9 @@ export default {
const res = await this.$axios.post(url, this.loginAccount) const res = await this.$axios.post(url, this.loginAccount)
console.debug('login user', res.data) console.debug('login user', res.data)
this.$store.commit('SET_TOKEN', res.data.token) this.$store.commit('SET_TOKEN', res.data.token)
const user = { ...res.data }
delete user.token
this.$store.commit('SET_USER', user)
this.$toast.success('Welcome back!') this.$toast.success('Welcome back!')
this.$router.push('/container') this.$router.push('/container')
} catch (err) { } catch (err) {
......
import VuexPersistence from 'vuex-persist'
export default ({ store }) => {
new VuexPersistence({
storage: window.localStorage,
reducer: state => ({
token: state.token,
user: state.user
})
}).plugin(store)
}
export const state = () => ({ export const state = () => ({
db: null, db: null,
token: null token: null,
user: null
}) })
export const mutations = { export const mutations = {
...@@ -9,5 +10,8 @@ export const mutations = { ...@@ -9,5 +10,8 @@ export const mutations = {
}, },
SET_TOKEN (state, token) { SET_TOKEN (state, token) {
state.token = token state.token = token
},
SET_USER (state, user) {
state.user = user
} }
} }
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment