Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Vue from 'vue'
- import Router from 'vue-router'
- import Dashboard from '@/components/Dashboard'
- import Login from '@/components/Login'
- import SignUp from '@/components/SingUp'
- import RecentPosts from '@/components/RecentPosts';
- import firebase from 'firebase'
- Vue.use(Router)
- let router = new Router({
- routes: [
- ...... some routes
- {
- path: '/recentPosts',
- name: 'RecentPosts',
- component: RecentPosts,
- meta:{
- requireAuth: true
- }
- }
- ]
- })
- router.beforeEach((to, from, next) => {
- let currentUser = firebase.auth().currentUser;
- let requiresAuth = to.matched.some(r => r.meta.requiresAuth);
- console.log("CURRENTUSER",currentUser);
- if(!currentUser && requiresAuth) {
- next('Login');
- }else if(currentUser && !requiresAuth) {
- next('Dashboard');
- }else if (currentUser && requiresAuth) {
- next();
- }else {
- next();
- }
- });
- export default router;
- else if (currentUser && requiresAuth) {
- next();
- }
Add Comment
Please, Sign In to add comment