diff --git a/src/components/LoginComponent.vue b/src/components/LoginComponent.vue index 66952bb..c39492d 100644 --- a/src/components/LoginComponent.vue +++ b/src/components/LoginComponent.vue @@ -56,7 +56,7 @@ export default { ...authStore.mapState(['field']), email: { get() { - return this.$store.state.AuthStore.form.email + return this.$store.state.AuthStore.email }, set(value) { this.$store.commit('AuthStore/email', value) @@ -64,7 +64,7 @@ export default { }, password: { get() { - return this.$store.state.AuthStore.form.password + return this.$store.state.AuthStore.password }, set(value) { this.$store.commit('AuthStore/password', value) @@ -78,11 +78,13 @@ export default { async onSubmit() { try { //console.log(authStore) - await this.$store.dispatch('AuthStore/login') + const params = { email: this.email, password: this.password } + await this.$store.dispatch('AuthStore/login', params) await this.$router.push({ name: this.$route.params.return_url || 'home' }) } catch (e) { + console.log(e) alert(e.message) } } diff --git a/src/service/token.service.js b/src/service/token.service.js index 297fac6..f8bbacc 100644 --- a/src/service/token.service.js +++ b/src/service/token.service.js @@ -19,7 +19,7 @@ class TokenService { return JSON.parse(localStorage.getItem('user')) } setUser(user) { - console.log('set User..' + JSON.stringify(user)) + console.log('set User..') localStorage.setItem('user', JSON.stringify(user)) } removeUser() { diff --git a/src/store/auth.store.js b/src/store/auth.store.js index cb281ed..a7ff14f 100644 --- a/src/store/auth.store.js +++ b/src/store/auth.store.js @@ -5,11 +5,9 @@ import tokenService from '../service/token.service' // count state 속성 추가 const state = { tokenService: tokenService, - form: { - email: null, - password: null, - name: null - }, + email: null, + password: null, + name: null, field: { email: { key: 'email', @@ -43,13 +41,13 @@ const getters = { } const mutations = { email: function (state, email) { - state.form.email = email + state.email = email }, password: function (state, password) { - state.form.password = password + state.password = password }, name: function (state, name) { - state.form.name = name + state.name = name }, login: function (state, user) { state.tokenService.setUser(user) @@ -64,9 +62,9 @@ const mutations = { const actions = { register: async function (context) { const params = { - email: this.form.email, - password: this.form.password, - name: this.form.name + email: state.email, + password: state.password, + name: state.name } await api.post('/auth/register', params).then((response) => { const { data } = response @@ -75,9 +73,7 @@ const actions = { } }) }, - login: async function ({ context, state }) { - const params = { email: state.form.email, password: state.form.password } - console.log(params) + login: async function (context, params) { await api.post('/auth/login', params).then((response) => { const { data } = response if (data.access_token) {