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) {
tonProof = await WebApp.initDataUnsafe.signData({ try {
data: authV1Token, tonProof = await WebApp.initDataUnsafe.signData({
}); 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,21 +31,25 @@ 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: { ? {
address: tonProof.address, account: {
// O.: add more as needed address: tonProof.address,
}, // O.: add more as needed
ton_proof: { },
signature: tonProof.signature, ton_proof: {
payload: tonProof.payload, signature: tonProof.signature,
// O.: add more as needed payload: tonProof.payload,
} // O.: add more as needed
} : undefined },
}
: undefined,
}).catch((error: any) => {
console.error("Error in authentication request: ", error);
throw new Error("Failed to authenticate.");
}); });
}); });
}; };