vue2_frontend...

This commit is contained in:
최준흠 2022-09-19 15:58:48 +09:00
parent 2e10604296
commit f1598a47a2
3 changed files with 16 additions and 18 deletions

View File

@ -56,7 +56,7 @@ export default {
...authStore.mapState(['field']), ...authStore.mapState(['field']),
email: { email: {
get() { get() {
return this.$store.state.AuthStore.form.email return this.$store.state.AuthStore.email
}, },
set(value) { set(value) {
this.$store.commit('AuthStore/email', value) this.$store.commit('AuthStore/email', value)
@ -64,7 +64,7 @@ export default {
}, },
password: { password: {
get() { get() {
return this.$store.state.AuthStore.form.password return this.$store.state.AuthStore.password
}, },
set(value) { set(value) {
this.$store.commit('AuthStore/password', value) this.$store.commit('AuthStore/password', value)
@ -78,11 +78,13 @@ export default {
async onSubmit() { async onSubmit() {
try { try {
//console.log(authStore) //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({ await this.$router.push({
name: this.$route.params.return_url || 'home' name: this.$route.params.return_url || 'home'
}) })
} catch (e) { } catch (e) {
console.log(e)
alert(e.message) alert(e.message)
} }
} }

View File

@ -19,7 +19,7 @@ class TokenService {
return JSON.parse(localStorage.getItem('user')) return JSON.parse(localStorage.getItem('user'))
} }
setUser(user) { setUser(user) {
console.log('set User..' + JSON.stringify(user)) console.log('set User..')
localStorage.setItem('user', JSON.stringify(user)) localStorage.setItem('user', JSON.stringify(user))
} }
removeUser() { removeUser() {

View File

@ -5,11 +5,9 @@ import tokenService from '../service/token.service'
// count state 속성 추가 // count state 속성 추가
const state = { const state = {
tokenService: tokenService, tokenService: tokenService,
form: {
email: null, email: null,
password: null, password: null,
name: null name: null,
},
field: { field: {
email: { email: {
key: 'email', key: 'email',
@ -43,13 +41,13 @@ const getters = {
} }
const mutations = { const mutations = {
email: function (state, email) { email: function (state, email) {
state.form.email = email state.email = email
}, },
password: function (state, password) { password: function (state, password) {
state.form.password = password state.password = password
}, },
name: function (state, name) { name: function (state, name) {
state.form.name = name state.name = name
}, },
login: function (state, user) { login: function (state, user) {
state.tokenService.setUser(user) state.tokenService.setUser(user)
@ -64,9 +62,9 @@ const mutations = {
const actions = { const actions = {
register: async function (context) { register: async function (context) {
const params = { const params = {
email: this.form.email, email: state.email,
password: this.form.password, password: state.password,
name: this.form.name name: state.name
} }
await api.post('/auth/register', params).then((response) => { await api.post('/auth/register', params).then((response) => {
const { data } = response const { data } = response
@ -75,9 +73,7 @@ const actions = {
} }
}) })
}, },
login: async function ({ context, state }) { login: async function (context, params) {
const params = { email: state.form.email, password: state.form.password }
console.log(params)
await api.post('/auth/login', params).then((response) => { await api.post('/auth/login', params).then((response) => {
const { data } = response const { data } = response
if (data.access_token) { if (data.access_token) {