Signup page (mostly) working
This commit is contained in:
20
src/hooks/AuthHooks.ts
Normal file
20
src/hooks/AuthHooks.ts
Normal 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(", "));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -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[];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user