added error handling
This commit is contained in:
parent
1b79b15a31
commit
afc1670ac0
|
|
@ -14,10 +14,15 @@ export const useAuth = () => {
|
|||
|
||||
let tonProof;
|
||||
if (authV1Token) {
|
||||
try {
|
||||
tonProof = await WebApp.initDataUnsafe.signData({
|
||||
data: authV1Token,
|
||||
});
|
||||
console.log("👀👀👀 tonProof: ", tonProof);
|
||||
} catch (error: any) {
|
||||
console.error("👀👀👀 Error signing data: ", error);
|
||||
throw new Error("Failed to sign data.");
|
||||
}
|
||||
}
|
||||
|
||||
return request.post<{
|
||||
|
|
@ -26,11 +31,11 @@ export const useAuth = () => {
|
|||
address: string;
|
||||
ton_balance: string;
|
||||
};
|
||||
|
||||
auth_v1_token: string;
|
||||
}>("/auth.twa", {
|
||||
twa_data: WebApp.initData,
|
||||
ton_proof: tonProof ? {
|
||||
ton_proof: tonProof
|
||||
? {
|
||||
account: {
|
||||
address: tonProof.address,
|
||||
// O.: add more as needed
|
||||
|
|
@ -39,8 +44,12 @@ export const useAuth = () => {
|
|||
signature: tonProof.signature,
|
||||
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.");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue