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.
 
 

104 line
4.1 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 = window.location.href.match("localhost:3000")?`${hostPath}/api`:(window.location.href.match(":3000")? "http://"+window.location.hostname+":8090/api":`/api`);
  12. export const paymentPath = window.location.href.match("localhost:3000")?`${hostPath}/payment`:`/payment`;
  13. /**
  14. * Testing:
  15. * Domain: apigw-isit.staging-eid.gov.hk
  16. * URL: hk.gov.iamsmart.testapp://
  17. *
  18. * Production
  19. * Domain: apigw.iamsmart.gov.hk
  20. * URL: hk.gov.iamsmart://
  21. */
  22. export const iAmSmartPath = `https://apigw-isit.staging-eid.gov.hk`;
  23. export const iAmSmartAppPath = `hk.gov.iamsmart.testapp://`;
  24. export const clientId = "cf61fa7c121e4869966f69c8694b1cd2";
  25. export const iAmSmartCallbackPath = () => {
  26. let hostname = window.location.hostname;
  27. if (hostname.match("pnspsuat")) {
  28. hostname = "pnspsuat.gld.gov.hk";
  29. }else{
  30. hostname = "pnspsdev.gld.gov.hk";
  31. }
  32. return hostname;
  33. };
  34. export const getNonce = () => {
  35. let hostname = window.location.hostname;
  36. if (hostname.match("localhost")) {
  37. hostname = "pnspsuat.gld.gov.hk";
  38. }
  39. return hostname;
  40. };
  41. export const getBowserType = () => {
  42. // console.log(navigator.userAgent)
  43. // const regex = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Mi|huawei|Opera Mini|SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i;
  44. // if(!regex.test(navigator.userAgent))
  45. if (navigator.userAgent.indexOf("Edg") != -1) {
  46. if (navigator.userAgent.match(/Android/i)) return "Android_Edge"
  47. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Edge"
  48. return "PC_Browser"
  49. } else if (navigator.userAgent.indexOf("Chrome") != -1) {
  50. if (navigator.userAgent.match(/Android/i)) return "Android_Chrome"
  51. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Chrome"
  52. return "PC_Browser"
  53. } else if (navigator.userAgent.indexOf("Safari") != -1) {
  54. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Safari"
  55. return "PC_Browser"
  56. } else if (navigator.userAgent.indexOf("Firefox") != -1) {
  57. if (navigator.userAgent.match(/Android/i)) return "Android_Firefox"
  58. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Firefox"
  59. return "PC_Browser"
  60. } else if (navigator.userAgent.match(/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i)) {
  61. return "Android_Samsung"
  62. } else if (navigator.userAgent.match(/huawei/i)) {
  63. return "Android_Huawei"
  64. } else if (navigator.userAgent.match(/Mi/i)) {
  65. return "Android_Xiaomi"
  66. }
  67. return "PC_Browser";
  68. }
  69. export const isAppBowser = () => {
  70. return "PC_Browser" != getBowserType();
  71. }
  72. export const isUserLoggedIn = () => {
  73. return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName);
  74. };
  75. export const getUserData = () => JSON.parse(localStorage.getItem('userData'));
  76. /**
  77. * This function is used for demo purpose route navigation
  78. * In real app you won't need this function because your app will navigate to same route for each users regardless of ability
  79. * Please note role field is just for showing purpose it's not used by anything in frontend
  80. * We are checking role just for ease
  81. * NOTE: If you have different pages to navigate based on user ability then this function can be useful. However, you need to update it.
  82. * @param {String} userRole Role of user
  83. */
  84. export const getHomeRouteForLoggedInUser = (userRole) => {
  85. if (userRole === 'admin') return '/';
  86. if (userRole === 'user') return '/';
  87. if (userRole === 'client') return { name: 'access-control' };
  88. return { name: 'auth-login' };
  89. };
  90. // open payment record
  91. export const local = {en:"en-us", zh:"zh-hk", cn:"zh-cn"};
  92. export const preferpaymentmethods = ['visa', 'mastercard', 'pps', 'creditcard', 'fps'];