Files
XHChat/web/src/main.ts
T

42 lines
1.5 KiB
TypeScript

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 { incomingGroupInvite, parseGroupInvite } from './chat/group-invites'
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 (to.path === '/groups' && typeof to.query.invite === 'string') {
incomingGroupInvite.value = parseGroupInvite(to.query.invite)
return { path: signedIn ? '/groups' : '/login', replace: true }
}
if (!signedIn && to.path !== '/login') return '/login'
if (signedIn && to.path === '/login') return '/devices'
})
createApp(App).use(pinia).use(router).mount('#app')