added error handling

This commit is contained in:
Oleg Yakovenko 2024-07-15 03:51:51 +03:00
parent 1b79b15a31
commit afc1670ac0
1 changed files with 25 additions and 16 deletions

View File

@ -14,10 +14,15 @@ export const useAuth = () => {
let tonProof; let tonProof;
if (authV1Token) { if (authV1Token) {
try {
tonProof = await WebApp.initDataUnsafe.signData({ tonProof = await WebApp.initDataUnsafe.signData({
data: authV1Token, data: authV1Token,
}); });
console.log("👀👀👀 tonProof: ", tonProof); console.log("👀👀👀 tonProof: ", tonProof);
} catch (error: any) {
console.error("👀👀👀 Error signing data: ", error);
throw new Error("Failed to sign data.");
}
} }
return request.post<{ return request.post<{
@ -26,11 +31,11 @@ export const useAuth = () => {
address: string; address: string;
ton_balance: string; ton_balance: string;
}; };
auth_v1_token: string; auth_v1_token: string;
}>("/auth.twa", { }>("/auth.twa", {
twa_data: WebApp.initData, twa_data: WebApp.initData,
ton_proof: tonProof ? { ton_proof: tonProof
? {
account: { account: {
address: tonProof.address, address: tonProof.address,
// O.: add more as needed // O.: add more as needed
@ -39,8 +44,12 @@ export const useAuth = () => {
signature: tonProof.signature, signature: tonProof.signature,
payload: tonProof.payload, payload: tonProof.payload,
// O.: add more as needed // O.: add more as needed
},
} }
} : undefined : undefined,
}).catch((error: any) => {
console.error("Error in authentication request: ", error);
throw new Error("Failed to authenticate.");
}); });
}); });
}; };