Skip to content

Commit

Permalink
Merge pull request #873 from /issues/857
Browse files Browse the repository at this point in the history
after deleting from temate autologout
  • Loading branch information
Pratap2018 authored Feb 4, 2022
2 parents 28da21d + 23c05bd commit fb4d994
Showing 1 changed file with 62 additions and 33 deletions.
95 changes: 62 additions & 33 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@ import Vue from "vue";
import Router from "vue-router";
import config from "./config";
import fetch from "node-fetch";
import eventBus from './eventBus';


import eventBus from "./eventBus";

Vue.use(Router);

const router = new Router({
mode: "history",
mode: "history",
routes: [
{
path: "/form/:slug",
name: "Event",
component: () => import(/* webpackChunkName: "investorLogin" */ './views/participant/Event.vue'),
meta: (route) => ({ requiresAuth: false, title: 'Hyperfyre - ' + route.params.slug, tabbar: false })
component: () =>
import(
/* webpackChunkName: "investorLogin" */ "./views/participant/Event.vue"
),
meta: (route) => ({
requiresAuth: false,
title: "Hyperfyre - " + route.params.slug,
tabbar: false,
}),
},
{
path: "/",
redirect: "/admin/login"
redirect: "/admin/login",
},
{
{
path: "/app",
redirect: "/admin/login",
},
Expand All @@ -32,17 +37,24 @@ const router = new Router({
{
path: "/invitation",
name: "Invitation",
component: () => import(/* webpackChunkName: "adminLogin" */ './views/Invitation.vue'),
component: () =>
import(/* webpackChunkName: "adminLogin" */ "./views/Invitation.vue"),
},
{
path: "/admin/login",
name: "AdminLogin",
component: () => import(/* webpackChunkName: "adminLogin" */ './views/admin/AdminLogin.vue'),
component: () =>
import(
/* webpackChunkName: "adminLogin" */ "./views/admin/AdminLogin.vue"
),
},
{
path: "/admin/dashboard",
name: "Dashboard",
component: () => import(/* webpackChunkName: "dashboard" */ './views/admin/Dashboard.vue') ,
component: () =>
import(
/* webpackChunkName: "dashboard" */ "./views/admin/Dashboard.vue"
),
meta: {
requiresAuth: true,
admin: true,
Expand All @@ -51,7 +63,10 @@ const router = new Router({
{
path: "/admin/teammate",
name: "Teammate",
component: () => import(/* webpackChunkName: "dashboard" */ './views/admin/TeamMate.vue') ,
component: () =>
import(
/* webpackChunkName: "dashboard" */ "./views/admin/TeamMate.vue"
),
meta: {
requiresAuth: true,
admin: true,
Expand All @@ -60,7 +75,10 @@ const router = new Router({
{
path: "/admin/participants",
name: "Participants",
component: () => import(/* webpackChunkName: "investors" */ './views/admin/Participants.vue') ,
component: () =>
import(
/* webpackChunkName: "investors" */ "./views/admin/Participants.vue"
),
meta: {
requiresAuth: true,
admin: true,
Expand All @@ -69,7 +87,8 @@ const router = new Router({
{
path: "/admin/events",
name: "Events",
component: () => import(/* webpackChunkName: "project" */ './views/admin/Events.vue') ,
component: () =>
import(/* webpackChunkName: "project" */ "./views/admin/Events.vue"),
meta: {
requiresAuth: true,
admin: true,
Expand All @@ -78,7 +97,10 @@ const router = new Router({
{
path: "/admin/subscription",
name: "subscription",
component: () => import(/* webpackChunkName: "subscription" */ './views/admin/Subscription.vue') ,
component: () =>
import(
/* webpackChunkName: "subscription" */ "./views/admin/Subscription.vue"
),
meta: {
requiresAuth: true,
admin: true,
Expand All @@ -88,20 +110,19 @@ const router = new Router({
});

router.beforeEach((to, from, next) => {
if(to.meta.title){
if (to.meta.title) {
document.title = to.meta.title;
}

if (to.matched.some((record) => record.meta.requiresAuth)) {
const authToken = localStorage.getItem("authToken");

if (authToken) {
// console.log("Yes auth token");
const url = `${config.studioServer.BASE_URL}hs/api/v2/auth/protected`;
fetch(url, {
headers: {
Authorization: `Bearer ${authToken}`,

},
method: "POST",
})
Expand All @@ -114,33 +135,41 @@ router.beforeEach((to, from, next) => {
});
} else {
localStorage.setItem("user", JSON.stringify(json.message));

Vue.prototype.$accounts=json.accounts
if (to.meta.admin && !json.message.isSubscribed && to.path != "/admin/subscription") {
eventBus.$emit('UpdateAdminNav', false);
Vue.prototype.$accounts = json.accounts;
if (json.accounts.length==0) {

localStorage.removeItem("accessToken")
localStorage.removeItem("accessuser")
}
if (
to.meta.admin &&
!json.message.isSubscribed &&
to.path != "/admin/subscription"
) {
eventBus.$emit("UpdateAdminNav", false);
next({
path: '/admin/subscription',
params: { nextUrl: to.fullPath }
})
path: "/admin/subscription",
params: { nextUrl: to.fullPath },
});
} else {
next()
next();
}
}
})
.catch((e) => {
console.log(e)
console.log(e);
next({
path: to.meta.admin ? "/admin/login" : "/login",
params: { nextUrl: to.fullPath },
});
});
} else {
next({
path: to.meta.admin ? "/admin/login" : (
!to.query["referrer"] ?
`/login/${to.params["slug"]}` :
`/login/${to.params["slug"]}?referrer=${to.query["referrer"]}`
),
path: to.meta.admin
? "/admin/login"
: !to.query["referrer"]
? `/login/${to.params["slug"]}`
: `/login/${to.params["slug"]}?referrer=${to.query["referrer"]}`,
params: { nextUrl: to.fullPath },
});
}
Expand Down

0 comments on commit fb4d994

Please sign in to comment.