From 1dcd26ffcf07b3f0a4a09c0c1b36f7432d157c0f Mon Sep 17 00:00:00 2001 From: Settel Date: Sun, 29 Jan 2023 15:36:06 +0100 Subject: [PATCH] add comments --- client/src/composables/useAuth.ts | 4 ++++ client/src/stores/ServerinfoStore.ts | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 client/src/stores/ServerinfoStore.ts diff --git a/client/src/composables/useAuth.ts b/client/src/composables/useAuth.ts index 43df1a8..c07243d 100644 --- a/client/src/composables/useAuth.ts +++ b/client/src/composables/useAuth.ts @@ -25,8 +25,11 @@ export default (): useAuth => { user.setUserInfo(userInfo) useI18n({}).setLang(userInfo.lang) if (allowRoles.indexOf(userInfo.role) >= 0 ) { + // user is authenticated and authorized, let the user in return } + + // user is authenticated but not authorized for this page if (user.isAdmin) { document.location.pathname = '/admin' // can't use navigateTo() for it fails with DOMException if two consecutive redirects happen (at least in docker container) @@ -35,6 +38,7 @@ export default (): useAuth => { document.location.pathname = '/play' } } catch (e) { + // user is not authenticated if (allowRoles.indexOf('') == -1 ) { document.location.pathname = '/' } diff --git a/client/src/stores/ServerinfoStore.ts b/client/src/stores/ServerinfoStore.ts new file mode 100644 index 0000000..722af8c --- /dev/null +++ b/client/src/stores/ServerinfoStore.ts @@ -0,0 +1,23 @@ +import { defineStore } from 'pinia' + +export type Serverinfo = { + isInitialized: boolean +} + +export const useServerinfoStore = defineStore('ServerinfoStore', { + state: () => { + return { + Serverinfo: { + isInitialized: false, + } as Serverinfo, + } + }, + getters: { + isInitialized: (state): boolean => state.Serverinfo.isInitialized, + }, + actions: { + setServerinfo(Serverinfo: Serverinfo): void { + this.Serverinfo = Serverinfo + }, + }, +})