您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

34 行
1.5 KiB

  1. import useJwt from 'auth/jwt/coreUseJwt'
  2. /**
  3. * Return if user is logged in
  4. * This is completely up to you and how you want to store the token in your frontend application
  5. * e.g. If you are using cookies to store the application please update this function
  6. */
  7. // eslint-disable-next-line arrow-body-style
  8. export const hostname = process.env.REACT_APP_BACKEND_HOST
  9. const hostPort = process.env.REACT_APP_BACKEND_PORT
  10. export const hostPath = `${process.env.REACT_APP_BACKEND_PROTOCOL}://${hostname}:${hostPort}`
  11. export const apiPath = `${hostPath}/api`
  12. export const isUserLoggedIn = () => {
  13. return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName)
  14. }
  15. export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
  16. /**
  17. * This function is used for demo purpose route navigation
  18. * In real app you won't need this function because your app will navigate to same route for each users regardless of ability
  19. * Please note role field is just for showing purpose it's not used by anything in frontend
  20. * We are checking role just for ease
  21. * NOTE: If you have different pages to navigate based on user ability then this function can be useful. However, you need to update it.
  22. * @param {String} userRole Role of user
  23. */
  24. export const getHomeRouteForLoggedInUser = userRole => {
  25. if (userRole === 'admin') return '/'
  26. if (userRole === 'user') return '/'
  27. if (userRole === 'client') return {name: 'access-control'}
  28. return {name: 'auth-login'}
  29. }