access.ts 372 B

1234567891011121314
  1. /**
  2. * @see https://umijs.org/zh-CN/plugins/plugin-access
  3. * */
  4. export default function access(initialState: { currentUser?: API.CurrentUser | undefined }) {
  5. const { currentUser, roles = [] } = initialState || {}
  6. return {
  7. authRouteFilter: route => {
  8. if (currentUser?.isAdmin) {
  9. return true
  10. }
  11. return roles.includes(route.name)
  12. }
  13. }
  14. }