比對新檔案 |
| | |
| | | import { Middleware } from '@nuxt/types'; |
| | | |
| | | |
| | | const isLogin: Middleware = (context) => { |
| | | const isUserLogin = context.store.getters['localStorage/isUserLogin']; |
| | | const isAdminLogin = context.store.getters['localStorage/isAdminLogin']; |
| | | const currentRouteName = context.route.name; |
| | | const noNeedLoginFunctionList = ['index', 'login', 'myConsultantList-consultantList', 'faq', 'consultantLogin', 'agentInfo-agentNo']; |
| | | |
| | | if (!isUserLogin && !isAdminLogin) { |
| | | if (!(noNeedLoginFunctionList.some((routeName) => routeName === currentRouteName))) { |
| | | context.redirect('/'); |
| | | } |
| | | } else if(isUserLogin) { |
| | | const userFunctions = ['accountSetting', 'userReviewsRecord', 'myConsultantList-consultantList', 'questionnaire-agentNo', ...noNeedLoginFunctionList]; |
| | | if (!(userFunctions.some((routeName) => routeName === currentRouteName))) { |
| | | context.redirect('/'); |
| | | } |
| | | } else if(isAdminLogin) { |
| | | const agentFunctions = ['agentInfo-agentNo', 'agentInfo-edit-agentNo', 'record', 'myAppointmentList-appointmentList', 'myAppointmentList-contactedList', 'myAppointmentList-closedList', 'appointment-appointmentId', 'appointment-appointmentId-close',...noNeedLoginFunctionList ]; |
| | | if (!(agentFunctions.some((routeName) => routeName === currentRouteName))) { |
| | | context.redirect('/'); |
| | | } |
| | | } |
| | | |
| | | console.log('isLogin_currentRouteName', currentRouteName); |
| | | |
| | | } |
| | | |
| | | export default isLogin |
| | |
| | | router: { |
| | | base: process.env.ENV === 'dev' ? '' : '/pam/', |
| | | mode: 'hash', |
| | | middleware: ['getUrlQuery', 'errorRoute'] |
| | | middleware: [ 'isLogin', 'getUrlQuery', 'errorRoute'] |
| | | } |
| | | } |