useRedirect.ts 806 B

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