bugfix: reset stores when user logs out

bugfix: ignore pending request that do not elong to current game
This commit is contained in:
Settel 2022-10-05 08:44:18 +02:00
parent 258067cf84
commit 582922a21a
7 changed files with 57 additions and 7 deletions

View File

@ -44,6 +44,12 @@ export async function fetchUpdate(this: EngineContext) {
throw Error('unexpected response from /api/sync')
}
if (response.game.id != userInfoStore.gameId) {
// happens when user changes game and an old request is still pending
console.warn('response gameId does not match current gameId')
return
}
this.version = parseInt(response.version)
this.isConnected.value = true
this.retry.value = 0

View File

@ -1,5 +1,9 @@
import { useUserinfoStore, Userinfo } from "@/stores/UserinfoStore"
import useI18n from "./useI18n"
import { useUserinfoStore, Userinfo } from '@/stores/UserinfoStore'
import { useEngineStore } from '@/stores/EngineStore'
import { useGameinfoStore } from '@/stores/GameinfoStore'
import { usePlayersStore } from '@/stores/PlayersStore'
import { useRoundStore } from '@/stores/RoundStore'
import useI18n from './useI18n'
import { $fetch } from 'ohmyfetch'
export type AllowRole = '' | 'player' | 'gamemaster' | 'admin'
@ -49,6 +53,11 @@ export default (): useAuth => {
logout: async (): Promise<void> => {
await $fetch('/api/logout')
useEngineStore().reset()
useGameinfoStore().reset()
usePlayersStore().reset()
useUserinfoStore().reset()
useRoundStore().reset()
},
}
}

View File

@ -10,5 +10,8 @@ export const useEngineStore = defineStore('EngineStore', {
setJson(json: any): void {
this.json = json
},
reset(): void {
this.json = {}
},
},
})

View File

@ -33,5 +33,13 @@ export const useGameinfoStore = defineStore('GameinfoStore', {
setGameinfo(gameInfo: Gameinfo): void {
this.gameInfo = gameInfo
},
reset(): void {
this.gameInfo = {
id: '',
name: '',
state: '',
phase: '',
}
},
},
})

View File

@ -12,5 +12,8 @@ export const usePlayersStore = defineStore('PlayersStore', {
players = players || []
this.players.splice(0, this.players.length, ...players)
},
reset(): void {
this.players.splice(0, 0)
},
},
})

View File

@ -24,5 +24,16 @@ export const useRoundStore = defineStore('RoundStore', {
this.round.revelation.votes = round.revelation?.votes || {} as RevelationVotes
this.round.revelation.sources = round.revelation?.sources || {} as RevelationSources
},
reset(): void {
this.round = {
quote: '',
sources: [],
selections: {},
revelation: {
votes: {},
sources: {},
},
}
},
},
})

View File

@ -34,5 +34,15 @@ export const useUserinfoStore = defineStore('UserinfoStore', {
setUserInfo(userInfo: Userinfo): void {
this.userInfo = userInfo
},
reset(): void {
this.userInfo = {
id: '',
name: '',
role: '',
game: '',
lang: 'en',
isCameo: '',
}
},
},
})