Skip to content
Snippets Groups Projects
Commit f83823fc authored by V S Tharunika's avatar V S Tharunika
Browse files

rectifying errors

parent a23289bf
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@
<v-toolbar-items style="padding-top: 50px;padding-bottom: 20px;padding-right: 20px;">
<router-link to="register">
<v-btn >
<v-btn v-if="!$store.state.isUserLoggedIn">
Sign Up
</v-btn>
</router-link>
......@@ -31,7 +31,7 @@
<v-toolbar-items style="padding-top: 50px;padding-bottom: 20px;">
<router-link to="login">
<v-btn>
<v-btn v-if="!$store.state.isUserLoggedIn">
Log In
</v-btn>
</router-link>
......
......@@ -33,10 +33,12 @@ export default {
methods: {
async login () {
try {
await AuthentiacationService.login({
const response = await AuthentiacationService.login({
email: this.email,
password: this.password
})
this.$store.dispatch('setToken', response.data.token)
this.$store.dispatch('setUser', response.data.user)
} catch (error) {
this.error = error.response.data.error
}
......
......@@ -35,10 +35,12 @@ export default {
methods: {
async register () {
try {
await AuthentiacationService.register({
const response = await AuthentiacationService.register({
email: this.email,
password: this.password
})
this.$store.dispatch('setToken', response.data.token)
this.$store.dispatch('setUser', response.data.user)
} catch (error) {
this.error = error.response.data.error
}
......
......@@ -4,16 +4,21 @@ import Vue from 'vue'
import App from './App'
import router from './router'
import Vuetify from 'vuetify'
import { sync } from 'vuex-router-sync'
import 'vuetify/dist/vuetify.min.css'
import store from '@/store/store'
Vue.config.productionTip = false
Vue.use(Vuetify)
sync(store, router)
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
components: { App },
template: '<App/>'
})
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
strict: true,
state: {
token: null,
user: null,
isUserLoggedIn: false
},
mutations: {
setToken (state, token) {
state.token = token
if (token) {
state.isUserLoggedIn = true
} else {
state.isUserLoggedIn = false
}
},
setUser (state, user) {
state.user = user
}
},
actions: {
setToken({commit}, token) {
commit('setToken', token)
},
setUser({commit}, user) {
commit('setUser', user)
}
}
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment