diff --git a/client/src/components/TopBar.vue b/client/src/components/TopBar.vue
index 344333e..daa8809 100644
--- a/client/src/components/TopBar.vue
+++ b/client/src/components/TopBar.vue
@@ -12,7 +12,7 @@
- {{ game.name }}
+ {{ game?.name }}
@@ -29,7 +29,7 @@ import useI18n from '@/composables/useI18n';
import { useUserinfoStore } from "@/stores/UserinfoStore"
import { useGameinfoStore } from "@/stores/GameinfoStore"
-const { $t, setLang } = useI18n({
+const { $t } = useI18n({
'logout': { en: 'Logout', de: 'abmelden' },
})
@@ -69,7 +69,8 @@ const actionLogout = async () => {
&__actionbar {
flex-grow: 1;
- &__player {
+ &__player,
+ &__admin {
font-size: 24px;
text-align: center;
}
diff --git a/client/src/composables/useAuth.ts b/client/src/composables/useAuth.ts
index 28a62c0..1d62b4e 100644
--- a/client/src/composables/useAuth.ts
+++ b/client/src/composables/useAuth.ts
@@ -1,19 +1,37 @@
-import { useUserinfoStore } from "@/stores/UserinfoStore"
+import { navigateTo } from "#app"
+import { useUserinfoStore, Userinfo } from "@/stores/UserinfoStore"
import { $fetch } from 'ohmyfetch'
+export type AllowRole = '' | 'player' | 'gamemaster' | 'admin'
+export type AllowRoles = Array
+
export interface useAuth {
login(authCode: string): Promise
logout(): Promise
- authenticateAndLoadUserInfo(): Promise
+ authenticateAndLoadUserInfo(allowRoles: AllowRoles): Promise
}
export default (): useAuth => {
- const userInfoStore = useUserinfoStore()
+ const user = useUserinfoStore()
return {
- authenticateAndLoadUserInfo: async (): Promise => {
- const userInfo = await $fetch('/api/userinfo')
- userInfoStore.setUserInfo(userInfo)
+ authenticateAndLoadUserInfo: async (allowRoles: AllowRoles): Promise => {
+ try {
+ const userInfo = await $fetch('/api/userinfo') as Userinfo
+ user.setUserInfo(userInfo)
+ if (allowRoles.indexOf(userInfo.role) >= 0 ) {
+ return
+ }
+ if (user.isAdmin) {
+ navigateTo('/admin', { replace: true })
+ } else {
+ navigateTo('/play', { replace: true })
+ }
+ } catch (e) {
+ if (allowRoles.indexOf('') == -1 ) {
+ navigateTo('/', { replace: true })
+ }
+ }
},
login: async (authCode: string): Promise => {
diff --git a/client/src/pages/admin.vue b/client/src/pages/admin.vue
new file mode 100644
index 0000000..be6cae5
--- /dev/null
+++ b/client/src/pages/admin.vue
@@ -0,0 +1,23 @@
+
+
+
+ Admin page
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client/src/pages/gamemaster.vue b/client/src/pages/gamemaster.vue
index 74eb904..1d698e6 100644
--- a/client/src/pages/gamemaster.vue
+++ b/client/src/pages/gamemaster.vue
@@ -2,32 +2,35 @@