Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdeexp 1951 lost device event does not emit whitelabel mfa provider #826

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7e790ad
feat: implement lost-device type for login with email otp
sherzod-bakhodirov Oct 21, 2024
19b4252
chore: update yarn.lock
sherzod-bakhodirov Oct 21, 2024
d766975
Merge pull request #825 from magiclabs/PDEEXP-1951-Lost-Device-Event-…
sherzod-bakhodirov Oct 21, 2024
4d71089
feat: implement lost-device event handler in loginWithEmailOTP method
sherzod-bakhodirov Oct 21, 2024
90a0aee
feat: add invalid-recovery-code type to loginWithEmailOtp
sherzod-bakhodirov Oct 21, 2024
78c5e41
Merge pull request #827 from magiclabs/PDEEXP-1951-Lost-Device-Event-…
sherzod-bakhodirov Oct 21, 2024
9f1b159
fix: deepsource error
sherzod-bakhodirov Oct 21, 2024
bca4fef
feat: add tests for login with email otp whitelabel
sherzod-bakhodirov Oct 22, 2024
d1d4d38
Merge branch 'master' into PDEEXP-1951-Lost-Device-Event-Does-Not-Emi…
Ethella Oct 22, 2024
00d330d
feat: seperate lost-device and verify-recovery-code for login with em…
sherzod-bakhodirov Oct 23, 2024
19b27a0
feat: add recovery-code-sent-handle event for login with email otp
sherzod-bakhodirov Oct 23, 2024
0eb553a
chore: update yarn.lock
sherzod-bakhodirov Oct 23, 2024
f377ca1
fix: update verify recovery code
sherzod-bakhodirov Oct 23, 2024
b5f797e
feat: add RecoveryCodeSuccess event for login with email otp
sherzod-bakhodirov Oct 24, 2024
e26191d
Merge branch 'master' into PDEEXP-1951-Lost-Device-Event-Does-Not-Emi…
sherzod-bakhodirov Oct 25, 2024
18364c7
feat: add tests for login with email otp whitelabel
sherzod-bakhodirov Oct 25, 2024
5cf62e9
Merge branch 'master' into PDEEXP-1951-Lost-Device-Event-Does-Not-Emi…
Ethella Oct 25, 2024
b5839f6
update yarn.lock
Ethella Oct 25, 2024
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
9 changes: 9 additions & 0 deletions packages/@magic-sdk/provider/src/modules/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ export class AuthModule extends BaseModule {
handle.on(LoginWithEmailOTPEventEmit.VerifyMFACode, (mfa: string) => {
this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.VerifyMFACode, requestPayload.id as string)(mfa);
});
handle.on(LoginWithEmailOTPEventEmit.LostDevice, () => {
this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.LostDevice, requestPayload.id as string)();
});
handle.on(LoginWithEmailOTPEventEmit.VerifyRecoveryCode, (recoveryCode: string) => {
this.createIntermediaryEvent(
LoginWithEmailOTPEventEmit.VerifyRecoveryCode,
requestPayload.id as string,
)(recoveryCode);
});
handle.on(LoginWithEmailOTPEventEmit.Cancel, () => {
this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.Cancel, requestPayload.id as any)();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,41 @@ test('Generates JSON RPC pending for verify-mfa-code', () => {
const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
expect(intermediaryEventSecondMethod).toBe('cancel');
});

test('Generates JSON RPC pending for lost-device', () => {
const magic = createMagicSDK();
magic.auth.overlay.post = jest.fn().mockImplementation(() => new Promise(() => {}));
const createIntermediaryEventFn = jest.fn();
magic.auth.createIntermediaryEvent = jest.fn().mockImplementation(() => createIntermediaryEventFn);

const handle = magic.auth.loginWithEmailOTP({ email: expectedEmail, showUI: false });

handle.emit('lost-device');
handle.emit('cancel');

const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0];
expect(verifyEvent[0]).toBe('lost-device');

const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
expect(intermediaryEventSecondMethod).toBe('cancel');
});

test('Generates JSON RPC pending for verify-recovery-code', () => {
const magic = createMagicSDK();
magic.auth.overlay.post = jest.fn().mockImplementation(() => new Promise(() => {}));
const createIntermediaryEventFn = jest.fn();
magic.auth.createIntermediaryEvent = jest.fn().mockImplementation(() => createIntermediaryEventFn);

const handle = magic.auth.loginWithEmailOTP({ email: expectedEmail, showUI: false });

const recovery_code = '10epf6fk';
handle.emit('verify-recovery-code', recovery_code);
handle.emit('cancel');

const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0];
expect(verifyEvent[0]).toBe('verify-recovery-code');
expect(createIntermediaryEventFn.mock.calls[0][0]).toBe(recovery_code);

const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
expect(intermediaryEventSecondMethod).toBe('cancel');
});
10 changes: 10 additions & 0 deletions packages/@magic-sdk/types/src/modules/auth-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export enum LoginWithMagicLinkEventOnReceived {
export enum LoginWithEmailOTPEventEmit {
VerifyEmailOtp = 'verify-email-otp',
VerifyMFACode = 'verify-mfa-code',
LostDevice = 'lost-device',
VerifyRecoveryCode = 'verify-recovery-code',
Cancel = 'cancel',
}

Expand All @@ -171,6 +173,9 @@ export enum LoginWithEmailOTPEventOnReceived {
InvalidMfaOtp = 'invalid-mfa-otp',
ExpiredEmailOtp = 'expired-email-otp',
MfaSentHandle = 'mfa-sent-handle',
RecoveryCodeSentHandle = 'recovery-code-sent-handle',
InvalidRecoveryCode = 'invalid-recovery-code',
RecoveryCodeSuccess = 'recovery-code-success',
}

export enum DeviceVerificationEventEmit {
Expand Down Expand Up @@ -278,12 +283,17 @@ export type LoginWithEmailOTPEventHandlers = {
[LoginWithEmailOTPEventOnReceived.InvalidMfaOtp]: () => void;
[LoginWithEmailOTPEventOnReceived.ExpiredEmailOtp]: () => void;
[LoginWithEmailOTPEventOnReceived.MfaSentHandle]: () => void;
[LoginWithEmailOTPEventOnReceived.RecoveryCodeSentHandle]: () => void;
[LoginWithEmailOTPEventOnReceived.InvalidRecoveryCode]: () => void;
[LoginWithEmailOTPEventOnReceived.RecoveryCodeSuccess]: () => void;
[AuthEventOnReceived.IDTokenCreated]: (idToken: string) => void;
[WalletEventOnReceived.WalletInfoFetched]: () => void;

// Event sent
[LoginWithEmailOTPEventEmit.VerifyEmailOtp]: (otp: string) => void;
[LoginWithEmailOTPEventEmit.VerifyMFACode]: (mfa: string) => void;
[LoginWithEmailOTPEventEmit.LostDevice]: () => void;
[LoginWithEmailOTPEventEmit.VerifyRecoveryCode]: (recoveryCode: string) => void;
[LoginWithEmailOTPEventEmit.Cancel]: () => void;
} & DeviceVerificationEventHandlers;

Expand Down
Loading
Loading