保誠-保戶業務員媒合平台
Tomas
2022-07-29 dca840c1377f61b454f27ccffd6b2161a92291be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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