import { createApp } from 'vue' import { createPinia } from 'pinia' import { createRouter, createWebHashHistory } from 'vue-router' import App from './App.vue' import AuthView from './views/AuthView.vue' import DeviceView from './views/DeviceView.vue' import ContactsView from './views/ContactsView.vue' import ChatView from './views/ChatView.vue' import GroupView from './views/GroupView.vue' import Workspace from './views/Workspace.vue' import { useSession } from './session' import './style.css' const pinia = createPinia() const router = createRouter({ history: createWebHashHistory(), routes: [ { path: '/', redirect: '/devices' }, { path: '/login', component: AuthView }, { path: '/', component: Workspace, children: [ { path: 'devices', component: DeviceView }, { path: 'contacts', component: ContactsView }, { path: 'chat/:user?', component: ChatView }, { path: 'groups/:id?', component: GroupView }, ] }, { path: '/:pathMatch(.*)*', redirect: '/' }, ], }) router.beforeEach((to) => { const signedIn = Boolean(useSession(pinia).identity) if (!signedIn && to.path !== '/login') return '/login' if (signedIn && to.path === '/login') return '/devices' }) createApp(App).use(pinia).use(router).mount('#app')