Working login/logout flow
This commit is contained in:
Родитель
a753baab92
Коммит
31484338b4
|
@ -28,6 +28,7 @@
|
|||
<v-spacer></v-spacer>
|
||||
|
||||
<v-btn
|
||||
v-if="!isAuthenticated"
|
||||
href="https://github.com/vuetifyjs/vuetify/releases/latest"
|
||||
target="_blank"
|
||||
text
|
||||
|
@ -35,6 +36,7 @@
|
|||
<span class="mr-2">Login with Speckle</span>
|
||||
<v-icon>mdi-open-in-new</v-icon>
|
||||
</v-btn>
|
||||
<v-btn v-else @click="$store.dispatch('logout')">Log out</v-btn>
|
||||
</v-app-bar>
|
||||
|
||||
<v-main>
|
||||
|
@ -56,5 +58,8 @@ export default {
|
|||
data: () => ({
|
||||
//
|
||||
}),
|
||||
computed: {
|
||||
isAuthenticated() { return this.$store.state.user != null}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
const TOKEN='SpeckleDemo.AuthToken'
|
||||
|
@ -25,20 +24,9 @@ export default new Vuex.Store({
|
|||
},
|
||||
actions: {
|
||||
logout(context) {
|
||||
fetch('http:localhost:3000/auth/logout', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
token: localStorage.getItem(TOKEN),
|
||||
refreshToken: localStorage.getItem(REFRESH_TOKEN)
|
||||
})
|
||||
}).then( () => {
|
||||
context.commit("setUser", null)
|
||||
localStorage.removeItem( TOKEN )
|
||||
localStorage.removeItem( REFRESH_TOKEN )
|
||||
})
|
||||
},
|
||||
async exchangeAccessCode(context, accessCode) {
|
||||
console.log('VUEX - Access code exchange', accessCode)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template lang="html">
|
||||
<div class="home">
|
||||
<v-btn @click="this.authRedirect">Login with Speckle</v-btn>
|
||||
<p>{{ this.$store.state.user }}</p>
|
||||
<p>{{ isAuthenticated }}</p>
|
||||
<p>{{ this.$store.state.serverInfo }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -24,6 +24,7 @@ export default {
|
|||
},
|
||||
},
|
||||
computed: {
|
||||
isAuthenticated() { return this.$store.state.user != null}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче