refactor(dashboard): fetch current player via /players/me

This commit is contained in:
zetaloop
2026-05-03 06:06:06 +08:00
parent 38ff65d51f
commit a0b61fbc44
3 changed files with 28 additions and 13 deletions
+14
View File
@@ -35,6 +35,20 @@ export async function getPlayerById(playerId: string): Promise<Player | undefine
}
}
export async function getMyPlayer(): Promise<Player | undefined> {
try {
return await httpJson<Player>("/api/v1/players/me", { cache: "no-store" })
} catch (error) {
if (error instanceof Error && error.message === "UNAUTHORIZED") {
throw error
}
if (isApiError(error) && error.code === 404) {
return undefined
}
throw error
}
}
export async function listPlayersByShop(shopId: string): Promise<Player[]> {
const players = await listPlayers()
return players.filter((player) => String(player.shopId) === shopId)