|
|
@@ -97,34 +97,69 @@ const router = createRouter({
|
|
|
|
|
|
router.beforeEach((to, _, next) => {
|
|
|
const token:string|null = sessionStorage.getItem('token');
|
|
|
- const role:string|null = sessionStorage.getItem('role')
|
|
|
+ const role:string|null = sessionStorage.getItem('role');
|
|
|
+ const storeId:string|null = sessionStorage.getItem('storeId');
|
|
|
|
|
|
if (to.meta.title) {
|
|
|
document.title = to.meta.title;
|
|
|
}
|
|
|
|
|
|
- if (token) {
|
|
|
- if(to.meta.permission) {
|
|
|
- if(to.meta.permission.includes(role!)) {
|
|
|
- next();
|
|
|
- }
|
|
|
- else {
|
|
|
- next('/404');
|
|
|
- }
|
|
|
- } else {
|
|
|
- next()
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(to.path === '/login') {
|
|
|
- next();
|
|
|
- }
|
|
|
- else if(to.path === '/register') {
|
|
|
+ // if (token) {
|
|
|
+ // if(to.meta.permission) {
|
|
|
+ // if(to.meta.permission.includes(role!)) {
|
|
|
+ // if (to.name === 'createProduct') {
|
|
|
+ // if (to.params.storeId === storeId) {
|
|
|
+ // next();
|
|
|
+ // } else {
|
|
|
+ // next('/404')
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // next();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // next('/404');
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // next()
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // if(to.path === '/login') {
|
|
|
+ // next();
|
|
|
+ // }
|
|
|
+ // else if(to.path === '/register') {
|
|
|
+ // next();
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // next('/login');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ if (!token) {
|
|
|
+ if (to.path === '/login' || to.path === '/register') {
|
|
|
next();
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
next('/login');
|
|
|
}
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ if (!to.meta.permission) {
|
|
|
+ next();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!to.meta.permission.includes(role!)) {
|
|
|
+ next('/404');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (to.name === 'createProduct' && to.params.storeId !== storeId) {
|
|
|
+ next('/404');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
});
|
|
|
|
|
|
|