You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 line
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 = 'localhost';
  9. const hostPort = '8090';
  10. export const hostPath = `http://${hostname}:${hostPort}`;
  11. //export const apiPath = `http://192.168.0.112:8090/api`;
  12. export const apiPath = `${hostPath}/api`;
  13. //export const apiPath = `/api`;
  14. export const isUserLoggedIn = () => {
  15. return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName);
  16. };
  17. export const getUserData = () => JSON.parse(localStorage.getItem('userData'));
  18. /**
  19. * This function is used for demo purpose route navigation
  20. * In real app you won't need this function because your app will navigate to same route for each users regardless of ability
  21. * Please note role field is just for showing purpose it's not used by anything in frontend
  22. * We are checking role just for ease
  23. * NOTE: If you have different pages to navigate based on user ability then this function can be useful. However, you need to update it.
  24. * @param {String} userRole Role of user
  25. */
  26. export const getHomeRouteForLoggedInUser = (userRole) => {
  27. if (userRole === 'admin') return '/';
  28. if (userRole === 'user') return '/';
  29. if (userRole === 'client') return { name: 'access-control' };
  30. return { name: 'auth-login' };
  31. };