Signup page (mostly) working

This commit is contained in:
2025-03-15 20:20:14 -04:00
parent 0eeedf1e3b
commit 49243a71a1
4 changed files with 127 additions and 14 deletions

20
src/hooks/AuthHooks.ts Normal file
View File

@@ -0,0 +1,20 @@
import { Account } from "@/interface/Account";
import { api } from "@/util/AxiosUtil";
import { useMutation } from "@tanstack/react-query";
export function useSignup(){
return useMutation({
mutationKey: ["signup"],
mutationFn: async (account: Account) => {
const response = await api.post("/auth/signup", account);
if(response.status !== 200){
throw new Error("Failed to signup");
}
else if(response.data.errors){
throw new Error(response.data.errors.join(", "));
}
}
});
}

View File

@@ -1,6 +1,7 @@
import { Game } from "@/interface/Game";
import { api } from "@/util/AxiosUtil";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { AxiosError } from "axios";
export function useGetGame(gameId: string, disabled: boolean){
@@ -33,16 +34,20 @@ export function useGetGames(page: number, pageSize: number, searchTerm?: string)
params.append("searchTerm", searchTerm);
}
const response = await api.get(`/game?${params}`);
//TODO: Change all queries to follow this pattern
try{
const response = await api.get(`/game?${params}`);
if(response.status !== 200){
throw new Error("Failed to get games");
return response.data as Game[];
}
else if(response.data.errors){
throw new Error(response.data.errors.join(", "));
catch(error){
if(error instanceof AxiosError && error.response?.data.errors){
throw new Error(error.response?.data.errors.join(", "));
}
else{
throw error;
}
}
return response.data as Game[];
}
});
}