refactor(dashboard): fetch current player via /players/me
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user