Skip to content

Commit

Permalink
working verification, custom sms params, need to fix delete suborgs p…
Browse files Browse the repository at this point in the history
…atch
  • Loading branch information
moe-dev committed Dec 11, 2024
1 parent a9b7ac0 commit 62951c7
Show file tree
Hide file tree
Showing 18 changed files with 698 additions and 24 deletions.
52 changes: 44 additions & 8 deletions examples/react-components/src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Import,
useTurnkey,
getSuborgs,
getVerifiedSuborgs,
OtpVerification,
TurnkeyThemeProvider,
} from "@turnkey/sdk-react";
Expand Down Expand Up @@ -59,6 +60,8 @@ export default function Dashboard() {
);
const [signature, setSignature] = useState<any>(null);
const [suborgId, setSuborgId] = useState<string>("");
const [isVerifiedEmail, setIsVerifiedEmail] = useState<boolean>(false);
const [isVerifiedPhone, setIsVerifiedPhone] = useState<boolean>(false);
const [user, setUser] = useState<any>("");
const [otpId, setOtpId] = useState("");
const [messageSigningResult, setMessageSigningResult] = useState<
Expand Down Expand Up @@ -92,6 +95,9 @@ export default function Dashboard() {
organizationId: suborgId,
otpType: "OTP_TYPE_SMS",
contact: phoneInput,
smsCustomization: {
template: "Your Turnkey Demo OTP is {{.OtpCode}}",
},
});
setOtpId(initAuthResponse?.otpId!);
};
Expand All @@ -110,11 +116,11 @@ export default function Dashboard() {
toast.error("Please enter a valid email address");
return;
}
const suborgs = await getSuborgs({
const suborgs = await getVerifiedSuborgs({
filterType: "EMAIL",
filterValue: emailInput,
}); //TODO change to get verified suborgs
if (suborgs!.organizationIds.length > 0) {
if (suborgs && suborgs!.organizationIds.length > 0) {
toast.error("Email is already connected to another account");
return;
}
Expand All @@ -139,11 +145,11 @@ export default function Dashboard() {
toast.error("Please enter a valid phone number.");
return;
}
const suborgs = await getSuborgs({
const suborgs = await getVerifiedSuborgs({
filterType: "PHONE_NUMBER",
filterValue: phoneInput,
}); //TODO change to get verified suborgs
if (suborgs!.organizationIds.length > 0) {
if (suborgs && suborgs!.organizationIds.length > 0) {
toast.error("Phone Number is already connected to another account");
return;
}
Expand All @@ -157,6 +163,9 @@ export default function Dashboard() {
organizationId: suborgId,
otpType: "OTP_TYPE_SMS",
contact: phoneInput,
smsCustomization: {
template: "Your Turnkey Demo OTP is {{.OtpCode}}",
},
});
setOtpId(initAuthResponse?.otpId!);
setIsEmailModalOpen(false);
Expand Down Expand Up @@ -296,6 +305,33 @@ export default function Dashboard() {
organizationId: suborgId!,
});
setWallets(walletsResponse.wallets);
if (userResponse.user.userEmail) {
const suborgs = await getVerifiedSuborgs({
filterType: "EMAIL",
filterValue: userResponse.user.userEmail,
});

if (
suborgs &&
suborgs!.organizationIds.length > 0 &&
suborgs!.organizationIds[0] == suborgId
) {
setIsVerifiedEmail(true);
}
}
if (userResponse.user.userPhoneNumber) {
const suborgs = await getVerifiedSuborgs({
filterType: "PHONE_NUMBER",
filterValue: userResponse.user.userPhoneNumber,
});
if (
suborgs &&
suborgs!.organizationIds.length > 0 &&
suborgs!.organizationIds[0] == suborgId
) {
setIsVerifiedPhone(true);
}
}

// Default to the first wallet if available
if (walletsResponse.wallets.length > 0) {
Expand Down Expand Up @@ -441,11 +477,11 @@ export default function Dashboard() {
<div className="labelContainer">
<img src="/mail.svg" className="iconSmall" />
<Typography>Email</Typography>
{user && user.userEmail && (
{user && user.userEmail && isVerifiedEmail && (
<span className="loginMethodDetails">{user.userEmail}</span>
)}
</div>
{user && user.userEmail ? (
{user && user.userEmail && isVerifiedEmail ? (
<CheckCircleIcon sx={{ color: "#4c48ff" }} />
) : (
<div onClick={handleOpenEmailModal}>
Expand All @@ -458,13 +494,13 @@ export default function Dashboard() {
<div className="labelContainer">
<img src="/phone.svg" className="iconSmall" />
<Typography>Phone</Typography>
{user && user.userPhoneNumber && (
{user && user.userPhoneNumber && isVerifiedPhone && (
<span className="loginMethodDetails">
{user.userPhoneNumber}
</span>
)}
</div>
{user && user.userPhoneNumber ? (
{user && user.userPhoneNumber && isVerifiedPhone ? (
<CheckCircleIcon sx={{ color: "#4c48ff" }} />
) : (
<div onClick={handleOpenPhoneModal}>
Expand Down
1 change: 1 addition & 0 deletions examples/react-components/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export default function AuthPage() {
configOrder={configOrder}
onHandleAuthSuccess={handleAuthSuccess}
onError={(errorMessage: string) => toast.error(errorMessage)}
customSmsMessage={"Your Turnkey Demo OTP is {{.OtpCode}}"}
/>
</div>
<div>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 62951c7

Please sign in to comment.