Browse Source

🔨 Fix session to remain persistent during refresh

Due to some issues with npm install, web was downgraded to docker:lts-alpine3.10 tag
main
Haris Razis 4 years ago
parent
commit
70e0c71f58
  1. 2
      web/Dockerfile
  2. 5378
      web/package-lock.json
  3. 3
      web/package.json
  4. 37
      web/src/store/index.ts
  5. 16
      web/src/views/Dashboard.vue

2
web/Dockerfile

@ -1,4 +1,4 @@
FROM node:latest FROM node:lts-alpine3.10
WORKDIR /usr/src/app/web WORKDIR /usr/src/app/web

5378
web/package-lock.json

File diff suppressed because it is too large

3
web/package.json

@ -16,7 +16,8 @@
"vue": "^3.0.0", "vue": "^3.0.0",
"vue-class-component": "^8.0.0-0", "vue-class-component": "^8.0.0-0",
"vue-router": "^4.0.0-0", "vue-router": "^4.0.0-0",
"vuex": "^4.0.0-0" "vuex": "^4.0.0-0",
"vuex-persistedstate": "^4.0.0-beta.1"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0", "@vue/cli-plugin-babel": "~4.5.0",

37
web/src/store/index.ts

@ -1,4 +1,5 @@
import {createStore} from 'vuex' import {createStore} from 'vuex'
import createPersistedState from "vuex-persistedstate";
import axios, {AxiosResponse} from "axios"; import axios, {AxiosResponse} from "axios";
import qs from 'qs' import qs from 'qs'
@ -40,13 +41,43 @@ export default createStore({
}, },
logout({commit}) { logout({commit}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
commit("logout"); axios({
resolve() method: 'post',
url: 'http://localhost:8000/auth/logout'
})
.then((resp: AxiosResponse) => {
commit("logout");
resolve(resp)
})
.catch((err: Error) => {
commit("logout");
commit('auth_error')
reject(err)
})
}) })
}, },
getUser({commit}) {
return new Promise((resolve, reject) => {
axios({
method: 'get',
url: 'http://localhost:8000/auth/current_user'
})
.then((resp: AxiosResponse) => {
console.log(resp)
commit("auth_success", resp.data);
resolve(resp)
})
.catch((err: Error) => {
console.log(err)
commit('auth_error')
reject(err)
})
})
}
}, },
modules: {}, modules: {},
getters: { getters: {
isLoggedIn: state => state.status, isLoggedIn: state => state.status,
} },
plugins: [createPersistedState()]
}) })

16
web/src/views/Dashboard.vue

@ -2,12 +2,22 @@
</template> </template>
<script> <script lang="ts">
export default { import {Vue} from 'vue-class-component';
name: "Dashboard"
export default class Dashboard extends Vue {
mounted() {
this.$store.dispatch('getUser')
.then(() => this.$router.push('/dashboard'))
.catch((err: Error) => {
console.log(err)
this.$router.push('/login')
})
}
} }
</script> </script>
<style scoped> <style scoped>
</style> </style>
Loading…
Cancel
Save