mirror of
https://github.com/Floriansylvain/SpaceMessenger.git
synced 2026-08-19 11:43:22 +02:00
That's a huge commit if you ask me
This commit is contained in:
+16
-5
@@ -1,5 +1,13 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import GroupSelection from '@/views/GroupSelection.vue'
|
||||
import { doc, getDoc } from "firebase/firestore"
|
||||
import { db } from '@/utils/firestore'
|
||||
import { useSessionStore } from '@/stores/useSessionStore'
|
||||
|
||||
async function isGroupOk(id: string): Promise<boolean> {
|
||||
const docSnap = await getDoc(doc(db, "groups", id))
|
||||
return docSnap.exists()
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -10,12 +18,15 @@ const router = createRouter({
|
||||
component: GroupSelection
|
||||
},
|
||||
{
|
||||
path: '/group',
|
||||
path: '/group/:groupId',
|
||||
name: 'Group',
|
||||
component: GroupSelection,
|
||||
// beforeEnter: (to, from) => {
|
||||
// return '/'
|
||||
// }
|
||||
component: () => import('@/views/Chat.vue'),
|
||||
beforeEnter: async (to, from) => {
|
||||
const sessionStore = useSessionStore()
|
||||
const userAllowed = await isGroupOk(to.params.groupId as string)
|
||||
if (!userAllowed) return '/'
|
||||
sessionStore.groupId = to.params.groupId as string
|
||||
}
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user