Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import WaveUI from '../../node_modules/wave-ui/src/wave-ui/core'
  2. import { authenticator, currentProfile } from '../services'
  3. const DEV_MODE = import.meta.env.VITE_DEV == 'true'
  4. async function log(to) {
  5. // if (DEV_MODE) {
  6. if (!currentProfile.isLoggedIn || !currentProfile.isComplete) {
  7. console.info(
  8. `[Guard Status debug]: Profile: ${currentProfile.id.value} | Login: ${currentProfile.isLoggedIn} | Complete: ${currentProfile.isComplete}`,
  9. )
  10. }
  11. console.info('[Guard Status debug]: being routed to:', to.fullPath)
  12. // }
  13. }
  14. const loginIfToken = async () => {
  15. const sessionData = await authenticator.checkSessionValid()
  16. if (
  17. sessionData?.profileId &&
  18. sessionData?.sessionToken
  19. ) {
  20. await currentProfile.login(
  21. sessionData.profileId,
  22. WaveUI.instance.notify,
  23. sessionData.sessionToken,
  24. )
  25. }
  26. }
  27. const checkLoginStatus = async (destination, nextCb) => {
  28. if(!currentProfile.isLoggedIn) {
  29. await loginIfToken()
  30. }
  31. log(destination)
  32. if (DEV_MODE) {
  33. nextCb()
  34. } else if (
  35. !currentProfile.isLoggedIn
  36. ) {
  37. nextCb('/login')
  38. } else if (
  39. destination.meta.requiresCompleteProfile &&
  40. destination.meta.requiresAuth
  41. ) {
  42. nextCb('/onboarding')
  43. } else {
  44. nextCb()
  45. }
  46. }
  47. export { checkLoginStatus }