add and use isAuthenticated method
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
export function getUser() {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
export function isAuthenticated() {
|
||||
return getUser().then(Boolean);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getUser } from '../lib/authentication';
|
||||
import { isAuthenticated } from '../lib/authentication';
|
||||
import TopNav from '../components/TopNav.vue';
|
||||
|
||||
export default {
|
||||
@@ -43,7 +43,7 @@
|
||||
return { name: 'customers' };
|
||||
}
|
||||
|
||||
return getUser().then(user => {
|
||||
return isAuthenticated().then(user => {
|
||||
const sendTo = getRedirect();
|
||||
// if already logged in, redirect
|
||||
if (user) return next(sendTo);
|
||||
|
||||
@@ -8,7 +8,7 @@ import Customers from './pages/Customers.vue';
|
||||
import Orders from './pages/Orders.vue';
|
||||
import About from './pages/About.vue';
|
||||
|
||||
import { getUser } from './lib/authentication';
|
||||
import { isAuthenticated } from './lib/authentication';
|
||||
|
||||
Vue.use(VueRouter);
|
||||
|
||||
@@ -51,7 +51,7 @@ const router = new VueRouter({
|
||||
router.beforeEach((to, from, next) => {
|
||||
// check if any of the matched routes require authentication
|
||||
if (to.matched.some(record => record.meta.requiresAuthentication)) {
|
||||
return getUser().then((user) => {
|
||||
return isAuthenticated().then((user) => {
|
||||
// if user is authenticated, continue
|
||||
if (user) return next();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user