diff --git a/web/src/main.ts b/web/src/main.ts index 28688bc..88e3751 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -8,5 +8,6 @@ import 'bulma/css/bulma.css'; import '@fortawesome/fontawesome-free/css/all.css'; import '@fortawesome/fontawesome-free/js/all.js'; -axios.defaults.withCredentials = true; +axios.defaults.baseURL = 'http://localhost:8000'; + createApp(App).use(store).use(router).mount('#app') diff --git a/web/src/store/index.ts b/web/src/store/index.ts index 41f41f8..a3e5290 100644 --- a/web/src/store/index.ts +++ b/web/src/store/index.ts @@ -26,7 +26,7 @@ export default createStore({ return new Promise((resolve, reject) => { axios({ method: 'post', - url: 'http://localhost:8000/auth/login', + url: '/auth/login', data: qs.stringify({...user}) }) .then((resp: AxiosResponse) => { @@ -43,7 +43,7 @@ export default createStore({ return new Promise((resolve, reject) => { axios({ method: 'post', - url: 'http://localhost:8000/auth/logout' + url: '/auth/logout' }) .then((resp: AxiosResponse) => { commit("logout"); @@ -56,19 +56,17 @@ export default createStore({ }) }) }, - getUser({commit}) { + getCurrentUser({commit}) { return new Promise((resolve, reject) => { axios({ method: 'get', - url: 'http://localhost:8000/auth/current_user' + url: '/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) }) diff --git a/web/src/views/Home.vue b/web/src/views/Home.vue index 22740f3..662fce9 100644 --- a/web/src/views/Home.vue +++ b/web/src/views/Home.vue @@ -48,5 +48,16 @@ import ShapeDividerTop from '@/components/ShapeDividerTop.vue'; }) export default class Home extends Vue { + mounted() { + this.getCurrentUser(); + } + + private getCurrentUser() { + this.$store.dispatch('getCurrentUser') + .then(() => this.$router.push('/dashboard')) + .catch((err: any) => { + this.$router.push('/') + }) + } } diff --git a/web/src/views/Login.vue b/web/src/views/Login.vue index 8725c99..2e23659 100644 --- a/web/src/views/Login.vue +++ b/web/src/views/Login.vue @@ -61,7 +61,8 @@ export default class Login extends Vue { this.$store.dispatch('login', user) .then(() => this.$router.push('/dashboard')) .catch((err: any) => { - this.msg = err.response.data.errors.message || err.message + console.log(err) + this.msg = err.response.data.errors.message || err.message || 'Something went wrong!' this.$router.push('/login') }) }