Skip to content

Commit

Permalink
changed requests format in widget
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushyadav1617 committed Nov 10, 2023
1 parent fc691b8 commit c455405
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 139 deletions.
150 changes: 81 additions & 69 deletions src/app/widget/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,21 @@ export default function Widget() {
}

try {
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${currentUserToken}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
usr: {
forget_password: true,
new_password: newPass
})
}
);
},
UserTokenBody: {
UserToken: currentUserToken
}
})
});

const data = (await response.json()) as {
detail?: string;
Expand Down Expand Up @@ -190,18 +192,20 @@ export default function Widget() {
return;
}
try {
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${currentUserToken}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
usr: {
new_user_password: newPass
})
}
);
},
UserTokenBody: {
UserToken: currentUserToken
}
})
});

const data = (await response.json()) as any;
setLoading2(false);
Expand Down Expand Up @@ -296,18 +300,20 @@ export default function Widget() {
return;
}
try {
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${currentUserToken}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
form_data: {
totp: otp
})
}
);
},
UserTokenBody: {
UserToken: currentUserToken
}
})
});
const data = (await response.json()) as any;
if (response.status === 202 || response.status === 203) {
setLoading2(false);
Expand Down Expand Up @@ -369,21 +375,23 @@ export default function Widget() {
if (storeOrgData.bot_det) {
rcToken = (await getCaptchaToken()) as string;
}
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${currentUserToken}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
form_data: {
email: email,
password: pass,
mfa_totp: otp ? otp : 0,
rc_token: rcToken
})
}
);
},
UserTokenBody: {
UserToken: currentUserToken
}
})
});
// console.log(response);
const data = (await response.json()) as any;
setLoading2(false);
Expand Down Expand Up @@ -459,21 +467,23 @@ export default function Widget() {
if (storeOrgData.bot_det) {
rcToken = (await getCaptchaToken()) as string;
}
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${currentUserToken}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
form_data: {
email: email,
password: pass,
mfa_totp: otp ? otp : 0,
rc_token: rcToken
})
}
);
},
UserTokenBody: {
UserToken: currentUserToken
}
})
});
// console.log(response);
const data = (await response.json()) as any;
setLoading2(false);
Expand Down Expand Up @@ -555,19 +565,21 @@ export default function Widget() {
return;
}
try {
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${currentUserToken}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
form_data: {
email: email,
mfa_totp: otp ? otp : 0
})
}
);
},
UserTokenBody: {
UserToken: currentUserToken
}
})
});
// console.log(response);
const data = (await response.json()) as any;
setLoading2(false);
Expand Down Expand Up @@ -1052,20 +1064,20 @@ export default function Widget() {
) : (
<div
style={bgStyle}
className="w-[100vw] h-[100vh] min-h-fit flex items-center justify-center"
className="w-[100vw] h-[100vh] overflow-y-scroll min-h-fit flex items-center justify-center"
>
<div
className={` h-full w-full flex ${
storeOrgData.decor_img ? 'flex-col 2md:flex-row' : ''
} items-center`}
>
<div
className={`flex items-center justify-center w-full ${
className={`flex items-center justify-center w-full py-10 ${
storeOrgData.decor_img ? '2md:w-2/3 ' : ''
} my-4`}
>
<Card
className="h-fit w-[423px] max-w-[90vw] max-h-[90vh] py-10 relative box-border px-[10%] sm:px-[67px] transition-all"
className="min-h-fit w-[423px] max-w-[90vw] py-10 relative box-border px-[10%] sm:px-[67px] transition-all"
style={cardStyle}
>
{showBack && (
Expand Down
54 changes: 29 additions & 25 deletions src/app/widget/profile/ProfileTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,28 @@ export default function Profile() {
toast({
variant: 'destructive',
title: 'Error!',
description: "please put a username first"
description: 'please put a username first'
});
return;
}
setLoading2(true);
try {
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${user_token}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
usr: {
Upd: {
full_name: username
}
})
}
);
},
UserTokenBody: {
UserToken: user_token
}
})
});
const data = (await response.json()) as {
detail?: string;
user_token: string;
Expand Down Expand Up @@ -103,7 +105,7 @@ export default function Profile() {
toast({
variant: 'destructive',
title: 'Error!',
description: "Some error occured with the request"
description: 'Some error occured with the request'
});
setLoading2(false);
return;
Expand Down Expand Up @@ -131,7 +133,7 @@ export default function Profile() {
toast({
variant: 'destructive',
title: 'Error!',
description: "Please add a file or URL first"
description: 'Please add a file or URL first'
});
setLoading1(false);
return;
Expand Down Expand Up @@ -200,20 +202,22 @@ export default function Profile() {
//request to save image
async function updateImage(url: string) {
try {
const response = await fetch(
`https://api.trustauthx.com/user/me/auth?UserToken=${user_token}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
usr: {
Upd: {
img: url
}
})
}
);
},
UserTokenBody: {
UserToken: user_token
}
})
});
const data = (await response.json()) as {
detail?: string;
user_token: string;
Expand Down
Loading

0 comments on commit c455405

Please sign in to comment.