Skip to content

Commit 14e6bdb

Browse files
committed
fearture: implement navigation guards, store mutations, store actions
1 parent 5b1b311 commit 14e6bdb

File tree

6 files changed

+72
-45
lines changed

6 files changed

+72
-45
lines changed

auth/credits.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Credits
22

3-
* Background Created by Quinky - Freepik.com https://www.freepik.com/free-photos-vectors/background
43
* UI by Enrico Deleo https://enricodeleo.com

auth/package-lock.json

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default {
4444
padding: 0;
4545
margin: 0;
4646
background-color: #f8f9f9;
47+
overflow-x: hidden;
4748
}
4849
4950
body {
@@ -83,5 +84,4 @@ export default {
8384
.header-main {
8485
margin-bottom: 20px;
8586
}
86-
8787
</style>

auth/src/main.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
// main.js
22
import Vue from 'vue';
3-
import App from './App.vue';
4-
import VueRouter from 'vue-router';
5-
6-
import { store } from './store';
7-
import IndexPage from './pages/Index';
8-
import LoginPage from './pages/Login';
9-
10-
const router = new VueRouter({
11-
routes: [
12-
{
13-
path: '/',
14-
name: 'index',
15-
component: IndexPage,
16-
},
17-
{
18-
path: '/login',
19-
name: 'login',
20-
component: LoginPage,
21-
},
22-
]
23-
});
243

25-
Vue.use(VueRouter);
4+
import App from './App.vue';
5+
import router from './router';
6+
import store from './store';
267

278
new Vue({
289
el: '#app',
2910
render: h => h(App),
3011
router,
3112
store,
32-
});
13+
});

auth/src/pages/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Index.vue
22
<template>
33
<div class="container">
4-
<img src="https://images.pexels.com/photos/1759406/pexels-photo-1759406.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
4+
Pagina profilo
55
</div>
66
</template>
77

auth/src/store/index.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,46 @@ Vue.use(Vuex);
55

66
const user = {
77
state: {
8+
id: null,
9+
registeredAt: null,
10+
avatar: null,
11+
name: null,
812
email: null,
9-
password: null,
13+
accessToken: null,
1014
},
11-
mutations: {},
12-
actions: {},
13-
getters: {}
14-
}
15+
mutations: {
16+
updateUser: (state, data) => {
17+
state = data;
18+
},
19+
logout: (state) => {
20+
state.accessToken = null;
21+
},
22+
},
23+
actions: {
24+
async doLogin({ commit }, loginData) {
25+
const rawResponse = await fetch('https://5dfd619831f32a0014c82843.mockapi.io/login', {
26+
method: 'POST',
27+
headers: {
28+
'Accept': 'application/json',
29+
'Content-Type': 'application/json'
30+
},
31+
body: JSON.stringify(loginData),
32+
});
33+
const response = await rawResponse.json();
34+
commit('updateUser', response);
35+
},
36+
37+
doLogout({ commit }) {
38+
commit('logout');
39+
}
40+
},
41+
getters: {},
42+
};
1543

1644
const store = new Vuex.Store({
1745
modules: {
1846
user,
19-
}
20-
})
47+
},
48+
});
2149

22-
export { store }
50+
export default store;

0 commit comments

Comments
 (0)