| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import { createRouter, createWebHistory } from "vue-router";
- import PaginaInicialView from "../views/pagina-inicial/PaginaInicialView.vue";
- import ConversasHistoricoView from "../views/conversas/ConversasHistoricoView.vue";
- import ConversasPesquisarView from "../views/conversas/ConversasPesquisarView.vue";
- import ConfiguracoesView from "../views/configuracoes/ConfiguracoesView.vue";
- import UsuariosView from "../views/usuarios/UsuariosView.vue";
- import LoginView from "../views/auth/LoginView.vue";
- import { useAuth } from "../composables/useAuth.js";
- export const router = createRouter({
- history: createWebHistory(import.meta.env.BASE_URL),
- routes: [
- { path: "/login", name: "login", component: LoginView, meta: { guestOnly: true } },
- { path: "/", name: "home", component: PaginaInicialView, meta: { requiresAuth: true } },
- { path: "/conversas/historico", name: "conversas-historico", component: ConversasHistoricoView, meta: { requiresAuth: true } },
- { path: "/conversas/pesquisar", name: "conversas-pesquisar", component: ConversasPesquisarView, meta: { requiresAuth: true } },
- { path: "/configuracoes", name: "configuracoes", component: ConfiguracoesView, meta: { requiresAuth: true } },
- { path: "/usuarios", name: "usuarios", component: UsuariosView, meta: { requiresAuth: true } },
- { path: "/:pathMatch(.*)*", redirect: "/" }
- ]
- });
- router.beforeEach((to) => {
- const { isAuthenticated } = useAuth();
- if (to.meta?.guestOnly && isAuthenticated.value) {
- return { name: "home" };
- }
- if (to.meta?.requiresAuth && !isAuthenticated.value) {
- return {
- name: "login",
- query: to.fullPath && to.fullPath !== "/" ? { redirect: to.fullPath } : {}
- };
- }
- return true;
- });
|