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. 3458
      web/package-lock.json
  3. 3
      web/package.json
  4. 35
      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

3458
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-class-component": "^8.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": {
"@vue/cli-plugin-babel": "~4.5.0",

35
web/src/store/index.ts

@ -1,4 +1,5 @@
import {createStore} from 'vuex'
import createPersistedState from "vuex-persistedstate";
import axios, {AxiosResponse} from "axios";
import qs from 'qs'
@ -40,13 +41,43 @@ export default createStore({
},
logout({commit}) {
return new Promise((resolve, reject) => {
axios({
method: 'post',
url: 'http://localhost:8000/auth/logout'
})
.then((resp: AxiosResponse) => {
commit("logout");
resolve()
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: {},
getters: {
isLoggedIn: state => state.status,
}
},
plugins: [createPersistedState()]
})

16
web/src/views/Dashboard.vue

@ -2,12 +2,22 @@
</template>
<script>
export default {
name: "Dashboard"
<script lang="ts">
import {Vue} from 'vue-class-component';
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>
<style scoped>
</style>
Loading…
Cancel
Save