useRedirect.ts 830 B

123456789101112131415161718192021222324252627282930313233
  1. import UrlUtils from '~/services/utils/urlUtils'
  2. export const useRedirect = () => {
  3. const runtimeConfig = useRuntimeConfig()
  4. const redirectToLogout = () => {
  5. const baseUrl =
  6. runtimeConfig.baseUrlAdminLegacy ??
  7. runtimeConfig.public.baseUrlAdminLegacy
  8. if (!baseUrl) {
  9. throw new Error('Configuration error : no redirection target')
  10. }
  11. navigateTo(UrlUtils.join(baseUrl, '#/logout'), {
  12. external: true,
  13. })
  14. }
  15. const redirectToHome = () => {
  16. const baseUrl =
  17. runtimeConfig.baseUrlAdminLegacy ??
  18. runtimeConfig.public.baseUrlAdminLegacy
  19. if (!baseUrl) {
  20. throw new Error('Configuration error : no redirection target')
  21. }
  22. navigateTo(UrlUtils.join(baseUrl, '#/dashboard'), {
  23. external: true,
  24. })
  25. }
  26. return { redirectToLogout, redirectToHome }
  27. }