You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For you to understand my doubt, I'm migrating my projet to Vite+Pinia+Ts+elementUI Plus. But I ran into a problem with my permissions
I can't use next({ ...to, replace: true })
when I load the page it works, when I press F5 the permission error
I'll leave some examples...
Previous version:
``
import router from './router'
import store from './store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import AuthService from '@/services/auth.service'
}
} else {
/* has no token*/
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
// other pages that do not have permission to access are redirected to the login page.
next(/login?redirect=${to.path})
NProgress.done()
}
}
})
})
router.afterEach(() => {
// finish progress bar
NProgress.done()
})
My version of now
import router from "@/router"
import { configure, start, done } from "nprogress"
import "nprogress/nprogress.css"
import AuthService from "@/utils/auth.service"
import { useUserStore } from "@/store/userAuth"
import { usePermissionStore } from "@/store/permission"
}
} else {
//Hasn't token
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
//Other pages that do not have permission to access are redirected to the login page.
next(/login?redirect=${to.path})
done()
}
}
})
})
router.afterEach(() => {
// finish progress bar
done()
})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
For you to understand my doubt, I'm migrating my projet to Vite+Pinia+Ts+elementUI Plus. But I ran into a problem with my permissions
I can't use next({ ...to, replace: true })
when I load the page it works, when I press F5 the permission error
I'll leave some examples...
Previous version:
``
import router from './router'
import store from './store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import AuthService from '@/services/auth.service'
NProgress.configure({ showSpinner: false })
const whiteList = ['/login']
router.beforeEach(async (to, from, next) => {
AuthService.validaLogin().then( async (resultValidaLogin) => {
const hasToken = resultValidaLogin
//Start progress bar
NProgress.start()
if (hasToken !== 'Invalido') {
if (to.path === '/login') {
next({ path: '/' })
NProgress.done()
} else {
const hasRoles = store.getters.userPermissionInfo.sAbreviatura && store.getters.userPermissionInfo.sAbreviatura.length > 0
if (hasRoles) {
next()
} else {
try {
const userPermissionInfo = await store.dispatch('permissionInfo')
const accessRoutes = await store.dispatch('permission/generateRoutes', userPermissionInfo)
router.addRoutes(accessRoutes)
}
} else {
/* has no token*/
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
// other pages that do not have permission to access are redirected to the login page.
next(
/login?redirect=${to.path}
)NProgress.done()
}
}
})
})
router.afterEach(() => {
// finish progress bar
NProgress.done()
})
My version of now
import router from "@/router"
import { configure, start, done } from "nprogress"
import "nprogress/nprogress.css"
import AuthService from "@/utils/auth.service"
import { useUserStore } from "@/store/userAuth"
import { usePermissionStore } from "@/store/permission"
configure({ showSpinner: false })
const whiteList = ['/login']
router.beforeEach((to, _from, next) => {
AuthService.validaLogin().then( async (hasToken) => {
//Start progress bar
start()
if(hasToken !== 'Invalido') {
if(to.path === whiteList[0]){
next({ path: '/' })
done()
} else {
try {
const userPermissionInfo = await useUserStore().userPermissionInfo
const accessRoutes = await usePermissionStore().generateRoutes(userPermissionInfo)
}
} else {
//Hasn't token
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
//Other pages that do not have permission to access are redirected to the login page.
next(
/login?redirect=${to.path}
)done()
}
}
})
})
router.afterEach(() => {
// finish progress bar
done()
})
Beta Was this translation helpful? Give feedback.
All reactions