bugfix: reset stores when user logs out
bugfix: ignore pending request that do not elong to current game
This commit is contained in:
parent
258067cf84
commit
582922a21a
@ -44,6 +44,12 @@ export async function fetchUpdate(this: EngineContext) {
|
|||||||
throw Error('unexpected response from /api/sync')
|
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.version = parseInt(response.version)
|
||||||
this.isConnected.value = true
|
this.isConnected.value = true
|
||||||
this.retry.value = 0
|
this.retry.value = 0
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import { useUserinfoStore, Userinfo } from "@/stores/UserinfoStore"
|
import { useUserinfoStore, Userinfo } from '@/stores/UserinfoStore'
|
||||||
import useI18n from "./useI18n"
|
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'
|
import { $fetch } from 'ohmyfetch'
|
||||||
|
|
||||||
export type AllowRole = '' | 'player' | 'gamemaster' | 'admin'
|
export type AllowRole = '' | 'player' | 'gamemaster' | 'admin'
|
||||||
@ -49,6 +53,11 @@ export default (): useAuth => {
|
|||||||
|
|
||||||
logout: async (): Promise<void> => {
|
logout: async (): Promise<void> => {
|
||||||
await $fetch('/api/logout')
|
await $fetch('/api/logout')
|
||||||
|
useEngineStore().reset()
|
||||||
|
useGameinfoStore().reset()
|
||||||
|
usePlayersStore().reset()
|
||||||
|
useUserinfoStore().reset()
|
||||||
|
useRoundStore().reset()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,8 @@ export const useEngineStore = defineStore('EngineStore', {
|
|||||||
setJson(json: any): void {
|
setJson(json: any): void {
|
||||||
this.json = json
|
this.json = json
|
||||||
},
|
},
|
||||||
|
reset(): void {
|
||||||
|
this.json = {}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -33,5 +33,13 @@ export const useGameinfoStore = defineStore('GameinfoStore', {
|
|||||||
setGameinfo(gameInfo: Gameinfo): void {
|
setGameinfo(gameInfo: Gameinfo): void {
|
||||||
this.gameInfo = gameInfo
|
this.gameInfo = gameInfo
|
||||||
},
|
},
|
||||||
|
reset(): void {
|
||||||
|
this.gameInfo = {
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
state: '',
|
||||||
|
phase: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -12,5 +12,8 @@ export const usePlayersStore = defineStore('PlayersStore', {
|
|||||||
players = players || []
|
players = players || []
|
||||||
this.players.splice(0, this.players.length, ...players)
|
this.players.splice(0, this.players.length, ...players)
|
||||||
},
|
},
|
||||||
|
reset(): void {
|
||||||
|
this.players.splice(0, 0)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -24,5 +24,16 @@ export const useRoundStore = defineStore('RoundStore', {
|
|||||||
this.round.revelation.votes = round.revelation?.votes || {} as RevelationVotes
|
this.round.revelation.votes = round.revelation?.votes || {} as RevelationVotes
|
||||||
this.round.revelation.sources = round.revelation?.sources || {} as RevelationSources
|
this.round.revelation.sources = round.revelation?.sources || {} as RevelationSources
|
||||||
},
|
},
|
||||||
|
reset(): void {
|
||||||
|
this.round = {
|
||||||
|
quote: '',
|
||||||
|
sources: [],
|
||||||
|
selections: {},
|
||||||
|
revelation: {
|
||||||
|
votes: {},
|
||||||
|
sources: {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -34,5 +34,15 @@ export const useUserinfoStore = defineStore('UserinfoStore', {
|
|||||||
setUserInfo(userInfo: Userinfo): void {
|
setUserInfo(userInfo: Userinfo): void {
|
||||||
this.userInfo = userInfo
|
this.userInfo = userInfo
|
||||||
},
|
},
|
||||||
|
reset(): void {
|
||||||
|
this.userInfo = {
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
role: '',
|
||||||
|
game: '',
|
||||||
|
lang: 'en',
|
||||||
|
isCameo: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user