add and use isAuthenticated method

This commit is contained in:
2017-02-14 20:37:16 -07:00
parent b800513800
commit faee26c586
3 changed files with 8 additions and 4 deletions

View File

@@ -1,3 +1,7 @@
export function getUser() { export function getUser() {
return Promise.resolve(null); return Promise.resolve(null);
} }
export function isAuthenticated() {
return getUser().then(Boolean);
}

View File

@@ -22,7 +22,7 @@
</template> </template>
<script> <script>
import { getUser } from '../lib/authentication'; import { isAuthenticated } from '../lib/authentication';
import TopNav from '../components/TopNav.vue'; import TopNav from '../components/TopNav.vue';
export default { export default {
@@ -43,7 +43,7 @@
return { name: 'customers' }; return { name: 'customers' };
} }
return getUser().then(user => { return isAuthenticated().then(user => {
const sendTo = getRedirect(); const sendTo = getRedirect();
// if already logged in, redirect // if already logged in, redirect
if (user) return next(sendTo); if (user) return next(sendTo);

View File

@@ -8,7 +8,7 @@ import Customers from './pages/Customers.vue';
import Orders from './pages/Orders.vue'; import Orders from './pages/Orders.vue';
import About from './pages/About.vue'; import About from './pages/About.vue';
import { getUser } from './lib/authentication'; import { isAuthenticated } from './lib/authentication';
Vue.use(VueRouter); Vue.use(VueRouter);
@@ -51,7 +51,7 @@ const router = new VueRouter({
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// check if any of the matched routes require authentication // check if any of the matched routes require authentication
if (to.matched.some(record => record.meta.requiresAuthentication)) { if (to.matched.some(record => record.meta.requiresAuthentication)) {
return getUser().then((user) => { return isAuthenticated().then((user) => {
// if user is authenticated, continue // if user is authenticated, continue
if (user) return next(); if (user) return next();