diff --git a/src/App.vue b/src/App.vue
index 1636025..3d52377 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -38,12 +38,24 @@
diff --git a/src/lib/authentication.js b/src/lib/authentication.js
deleted file mode 100644
index b06a17f..0000000
--- a/src/lib/authentication.js
+++ /dev/null
@@ -1,7 +0,0 @@
-export function getUser() {
- return Promise.resolve(null);
-}
-
-export function isAuthenticated() {
- return getUser().then(Boolean);
-}
diff --git a/src/main.js b/src/main.js
index 3bcc429..ad41901 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,21 +1,17 @@
import Vue from 'vue';
import router from './router';
import store from './store';
-import { isAuthenticated } from './lib/authentication';
// pre-route auth checking
router.beforeEach((to, from, next) => {
// check if any of the matched routes require authentication
if (to.matched.some(record => record.meta.requiresAuthentication)) {
- return isAuthenticated().then((user) => {
- // if user is authenticated, continue
- if (user) return next();
+ if (store.getters.isAuthenticated) return next();
- // otherwise, redirect to login, preserving the requested route
- const { name, fullPath } = to;
- const query = (name !== undefined) ? { redirect: name } : { prev: fullPath };
- return next({ name: 'login', query });
- });
+ // otherwise, redirect to login, preserving the requested route
+ const { name, fullPath } = to;
+ const query = (name !== undefined) ? { redirect: name } : { prev: fullPath };
+ return next({ name: 'login', query });
}
return next();
diff --git a/src/pages/Login.vue b/src/pages/Login.vue
index d8d99d0..638b6ed 100644
--- a/src/pages/Login.vue
+++ b/src/pages/Login.vue
@@ -24,6 +24,7 @@
\ No newline at end of file
diff --git a/src/router.js b/src/router/index.js
similarity index 76%
rename from src/router.js
rename to src/router/index.js
index ceb8f79..04d8d96 100644
--- a/src/router.js
+++ b/src/router/index.js
@@ -1,12 +1,12 @@
import Vue from 'vue';
import VueRouter from 'vue-router';
-import App from './App.vue';
+import App from '../App.vue';
-import Login from './pages/Login.vue';
-import Customers from './pages/Customers.vue';
-import Orders from './pages/Orders.vue';
-import About from './pages/About.vue';
+import Login from '../pages/Login.vue';
+import Customers from '../pages/Customers.vue';
+import Orders from '../pages/Orders.vue';
+import About from '../pages/About.vue';
Vue.use(VueRouter);
diff --git a/src/store/authentication.js b/src/store/authentication.js
new file mode 100644
index 0000000..2beef1c
--- /dev/null
+++ b/src/store/authentication.js
@@ -0,0 +1,10 @@
+export default {
+ state: {
+ user: null,
+ },
+ getters: {
+ isAuthenticated(state) {
+ return state.user !== null;
+ },
+ },
+};
diff --git a/src/store.js b/src/store/index.js
similarity index 61%
rename from src/store.js
rename to src/store/index.js
index 241355c..35cbaf4 100644
--- a/src/store.js
+++ b/src/store/index.js
@@ -1,11 +1,16 @@
import Vue from 'vue';
import Vuex from 'vuex';
+import authentication from './authentication';
+
Vue.use(Vuex);
const store = new Vuex.Store({
state: {
},
+ modules: {
+ authentication,
+ },
});
export default store;