Skip to content

Commit

Permalink
fix getPlayPuzzle response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent550102 committed Feb 25, 2024
1 parent 75a3fe0 commit 8c46fbe
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/lib/getPlayerPuzzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ async function sha1(str: string) {

export async function getPlayerPuzzle(playerToken: string) {
return sha1(playerToken)
.then(publicToken => fetch(`${API_URL}/event/puzzle?token=${publicToken}`))
.then(res => res.json())
.then(data => data.puzzle.length as number)
.then((publicToken) =>
fetch(`${API_URL}/event/puzzle?token=${publicToken}`)
)
.then((res) => res.json())
.then((data) => {
console.log(data);
if (data.message && data.message.startsWith("Invalid token")) {
return data.message;
} else {
return data.puzzles.length as number;
}
});
}

0 comments on commit 8c46fbe

Please sign in to comment.