import { createRouter, createWebHistory } from 'vue-router'; import ChatLayout from '../components/ChatLayout.vue'; import WalletConnect from '../components/WalletConnect.vue'; import { useChatStore } from '../stores/chat'; const routes = [ { path: '/', redirect: '/chat/nebula' }, { path: '/chat/:channel?', name: 'Chat', component: ChatLayout, meta: { requiresAuth: true }, props: true }, { path: '/profile/:address?', name: 'Profile', component: ChatLayout, meta: { requiresAuth: true }, props: route => ({ viewProfile: true, profileAddress: route.params.address }) }, { path: '/docs', name: 'Docs', component: ChatLayout, meta: { requiresAuth: true }, props: { viewDocs: true } }, { path: '/changelog', name: 'Changelog', component: ChatLayout, meta: { requiresAuth: true }, props: { viewChangelog: true } }, { path: '/login', name: 'Login', component: WalletConnect } ]; const router = createRouter({ history: createWebHistory(), routes }); router.beforeEach((to, from, next) => { const chatStore = useChatStore(); const isAuthenticated = chatStore.checkAuth(); if (to.meta.requiresAuth && !isAuthenticated) { next('/login'); } else if (to.path === '/login' && isAuthenticated) { next('/chat/nebula'); } else { next(); } }); export default router;