Move loginRequired state into store, reset login related state in RESET

This commit is contained in:
James Lyne 2021-09-07 23:10:57 +01:00
parent b2f58f681c
commit 12632004d1
5 changed files with 19 additions and 15 deletions

View File

@ -56,9 +56,9 @@ export default defineComponent({
chatBoxEnabled = computed(() => store.state.components.chatBox), chatBoxEnabled = computed(() => store.state.components.chatBox),
chatVisible = computed(() => store.state.ui.visibleElements.has('chat')), chatVisible = computed(() => store.state.ui.visibleElements.has('chat')),
loginEnabled = computed(() => store.state.components.login), //Whether logging in is enabled for the current server
loggedIn = computed(() => store.state.loggedIn), //Whether the user is currently logged in loggedIn = computed(() => store.state.loggedIn), //Whether the user is currently logged in
loginRequired = ref(false), //Whether logging is required to view the current server loginRequired = computed(() => store.state.loginRequired), //Whether logging is required to view the current server
loginEnabled = computed(() => store.state.components.login || loginRequired.value), //Whether logging in is enabled for the current server
//Hide the login modal if we are logged out on a login-required server, but the server list is open //Hide the login modal if we are logged out on a login-required server, but the server list is open
//Allows switching servers without the modal overlapping //Allows switching servers without the modal overlapping
@ -79,8 +79,6 @@ export default defineComponent({
await store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined); await store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined);
await store.dispatch(ActionTypes.START_UPDATES, undefined); await store.dispatch(ActionTypes.START_UPDATES, undefined);
loginRequired.value = false;
requestAnimationFrame(() => { requestAnimationFrame(() => {
hideSplash(); hideSplash();
@ -96,9 +94,8 @@ export default defineComponent({
return; return;
} }
//Logging in is required, show login modal //Logging in is required
if(e.message === 'login-required') { if(loginRequired.value) {
loginRequired.value = true;
return; return;
} }
@ -211,6 +208,8 @@ export default defineComponent({
store.commit(MutationTypes.SHOW_UI_MODAL, 'login'); store.commit(MutationTypes.SHOW_UI_MODAL, 'login');
notify('Login required'); notify('Login required');
showSplashError('Login required', true, 1); showSplashError('Login required', true, 1);
} else {
store.commit(MutationTypes.HIDE_UI_MODAL, 'login');
} }
}) })

View File

@ -629,8 +629,7 @@ export default class DynmapMapProvider extends MapProvider {
const response = await DynmapMapProvider.getJSON(this.config.dynmap!.configuration, this.configurationAbort.signal); const response = await DynmapMapProvider.getJSON(this.config.dynmap!.configuration, this.configurationAbort.signal);
if(response.error === 'login-required') { if(response.error === 'login-required') {
this.store.commit(MutationTypes.SET_LOGGED_IN, false); this.store.commit(MutationTypes.SET_LOGIN_REQUIRED, true);
this.store.commit(MutationTypes.SET_COMPONENTS, {login: true});
} }
if (response.error) { if (response.error) {
@ -813,7 +812,7 @@ export default class DynmapMapProvider extends MapProvider {
async login(data: any) { async login(data: any) {
const store = useStore(); const store = useStore();
if (!store.state.components.login) { if (!store.state.components.login && !store.state.loginRequired) {
return Promise.reject(store.state.messages.loginErrorDisabled); return Promise.reject(store.state.messages.loginErrorDisabled);
} }
@ -852,7 +851,7 @@ export default class DynmapMapProvider extends MapProvider {
async logout() { async logout() {
const store = useStore(); const store = useStore();
if (!store.state.components.login) { if (!store.state.components.login && !store.state.loginRequired) {
return Promise.reject(store.state.messages.loginErrorDisabled); return Promise.reject(store.state.messages.loginErrorDisabled);
} }
@ -870,7 +869,7 @@ export default class DynmapMapProvider extends MapProvider {
async register(data: any) { async register(data: any) {
const store = useStore(); const store = useStore();
if (!store.state.components.login) { if (!store.state.components.login && !store.state.loginRequired) {
return Promise.reject(store.state.messages.loginErrorDisabled); return Promise.reject(store.state.messages.loginErrorDisabled);
} }

View File

@ -385,9 +385,6 @@ export default class Pl3xmapMapProvider extends MapProvider {
this.store.commit(MutationTypes.SET_SERVER_MESSAGES, Pl3xmapMapProvider.buildMessagesConfig(response)); this.store.commit(MutationTypes.SET_SERVER_MESSAGES, Pl3xmapMapProvider.buildMessagesConfig(response));
this.store.commit(MutationTypes.SET_WORLDS, this.buildWorlds(response, worldResponses)); this.store.commit(MutationTypes.SET_WORLDS, this.buildWorlds(response, worldResponses));
this.store.commit(MutationTypes.SET_COMPONENTS, Pl3xmapMapProvider.buildComponents(response)); this.store.commit(MutationTypes.SET_COMPONENTS, Pl3xmapMapProvider.buildComponents(response));
//Pl3xmap has no login functionality
this.store.commit(MutationTypes.SET_LOGGED_IN, false);
} }
async populateWorld(world: LiveAtlasWorldDefinition) { async populateWorld(world: LiveAtlasWorldDefinition) {

View File

@ -59,5 +59,6 @@ export enum MutationTypes {
TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE = 'toggleSidebarSectionCollapsedState', TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE = 'toggleSidebarSectionCollapsedState',
SET_LOGGED_IN = 'setLoggedIn', SET_LOGGED_IN = 'setLoggedIn',
SET_LOGIN_REQUIRED = 'setLoginRequired',
RESET = 'reset' RESET = 'reset'
} }

View File

@ -92,6 +92,7 @@ export type Mutations<S = State> = {
[MutationTypes.TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE](state: S, section: LiveAtlasSidebarSection): void [MutationTypes.TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE](state: S, section: LiveAtlasSidebarSection): void
[MutationTypes.SET_LOGGED_IN](state: S, payload: boolean): void [MutationTypes.SET_LOGGED_IN](state: S, payload: boolean): void
[MutationTypes.SET_LOGIN_REQUIRED](state: S, payload: boolean): void
[MutationTypes.RESET](state: S): void [MutationTypes.RESET](state: S): void
} }
@ -620,6 +621,10 @@ export const mutations: MutationTree<State> & Mutations = {
state.loggedIn = payload; state.loggedIn = payload;
}, },
[MutationTypes.SET_LOGIN_REQUIRED](state: State, payload: boolean): void {
state.loginRequired = payload;
},
//Cleanup for switching servers or reloading the configuration //Cleanup for switching servers or reloading the configuration
[MutationTypes.RESET](state: State): void { [MutationTypes.RESET](state: State): void {
state.followTarget = undefined; state.followTarget = undefined;
@ -661,5 +666,8 @@ export const mutations: MutationTree<State> & Mutations = {
state.ui.visibleModal = undefined; state.ui.visibleModal = undefined;
state.chat.messages = []; state.chat.messages = [];
state.loggedIn = false;
state.loginRequired = false;
} }
} }