Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
start adding recovery flow
  • Loading branch information
ikethirdweb committed Oct 19, 2023
commit 2ba78b2627d6e7f7d3b101f456e4bafe659bbcc5
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class EmbeddedWalletConnector extends Connector<EmbeddedWalletConnectionA
}

switch (options?.loginType) {
case "google_oauth":
case "headless_google_oauth":
{
await socialLogin(
{
Expand All @@ -56,11 +56,11 @@ export class EmbeddedWalletConnector extends Connector<EmbeddedWalletConnectionA
);
}
break;
case "email_otp_verification": {
case "headless_email_otp_verification": {
await this.validateEmailOtp(options.otp);
break;
}
case "custom_jwt": {
case "custom_jwt_auth": {
await this.customJwt({
jwtToken: options.jwtToken,
encryptionKey: options.encryptionKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,9 @@ export async function sendEmailOTP(
email,
});

// AWS Auth flow
let cognitoUser: CognitoUser;
let userDetails: Awaited<ReturnType<typeof getEmbeddedWalletUserDetail>>;
try {
cognitoUser = await cognitoEmailSignIn(email, clientId);
} catch (e) {
await cognitoEmailSignUp(email, clientId);
cognitoUser = await cognitoEmailSignIn(email, clientId);
}
setCognitoUser(cognitoUser);

let result: Awaited<ReturnType<typeof getEmbeddedWalletUserDetail>>;
try {
result = await getEmbeddedWalletUserDetail({
userDetails = await getEmbeddedWalletUserDetail({
email,
clientId,
});
Expand All @@ -63,19 +53,34 @@ export async function sendEmailOTP(
);
}

return result.isNewUser
if (
userDetails.recoveryShareManagement === RecoveryShareManagement.AWS_MANAGED
) {
// AWS Auth flow
let cognitoUser: CognitoUser;
try {
cognitoUser = await cognitoEmailSignIn(email, clientId);
} catch (e) {
await cognitoEmailSignUp(email, clientId);
cognitoUser = await cognitoEmailSignIn(email, clientId);
}
setCognitoUser(cognitoUser);
} else {
}

return userDetails.isNewUser
? {
isNewUser: result.isNewUser,
isNewUser: userDetails.isNewUser,
isNewDevice: true,
recoveryShareManagement: RecoveryShareManagement.AWS_MANAGED,
recoveryShareManagement: userDetails.recoveryShareManagement,
}
: {
isNewUser: result.isNewUser,
isNewUser: userDetails.isNewUser,
isNewDevice: !(await isDeviceSharePresentForUser(
clientId,
result.walletUserId ?? "",
userDetails.walletUserId ?? "",
)),
recoveryShareManagement: RecoveryShareManagement.AWS_MANAGED,
recoveryShareManagement: userDetails.recoveryShareManagement,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export async function getEmbeddedWalletUserDetail(args: {
const result = (await resp.json()) as
| {
isNewUser: true;
recoveryShareManagement: RecoveryShareManagement;
}
| {
isNewUser: false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ export type EmbeddedWalletConnectionArgs = {
chainId?: number;
} & (
| {
loginType: "google_oauth";
loginType: "headless_google_oauth";
redirectUrl: string;
}
| {
loginType: "email_otp_verification";
loginType: "headless_email_otp_verification";
email: string;
otp: string;
}
| {
loginType: "custom_jwt";
loginType: "custom_jwt_auth";
jwtToken: string;
encryptionKey: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const EmbeddedConnectionUI: React.FC<ConnectUIProps<EmbeddedWallet>> = ({
setTimeout(() => {
(selectionData.emailWallet as EmbeddedWallet)
.connect({
loginType: "email_otp_verification",
loginType: "headless_email_otp_verification",
otp,
email: selectionData.email,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const EmbeddedSocialConnection: React.FC<
setTimeout(() => {
(selectionData.emailWallet as EmbeddedWallet)
.connect({
loginType: "google_oauth",
loginType: "headless_google_oauth",
redirectUrl: selectionData.oauthOptions?.redirectUrl,
})
.then(async (response) => {
Expand Down