Skip to content

Commit fd7963d

Browse files
authored
Revert "feat(passport): ID-3764 Debounce login (#2651)"
This reverts commit 4ae8530.
1 parent d2c766e commit fd7963d

2 files changed

Lines changed: 1 addition & 105 deletions

File tree

packages/passport/sdk/src/Passport.test.ts

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -550,94 +550,6 @@ describe('Passport', () => {
550550
expect(getUserMock).toBeCalledTimes(1);
551551
expect(authLoginMock).toBeCalledTimes(1);
552552
});
553-
554-
it('should debounce concurrent login calls and return the same result', async () => {
555-
getUserMock.mockReturnValue(null);
556-
authLoginMock.mockReturnValue(mockUserImx);
557-
558-
// Make multiple concurrent login calls
559-
const loginPromise1 = passport.login();
560-
const loginPromise2 = passport.login();
561-
const loginPromise3 = passport.login();
562-
563-
// All promises should be the same reference
564-
expect(loginPromise1).toEqual(loginPromise2);
565-
expect(loginPromise2).toEqual(loginPromise3);
566-
567-
// Wait for all to complete
568-
const [result1, result2, result3] = await Promise.all([
569-
loginPromise1,
570-
loginPromise2,
571-
loginPromise3,
572-
]);
573-
574-
// All results should be the same
575-
expect(result1).toEqual(mockUserImx.profile);
576-
expect(result2).toEqual(mockUserImx.profile);
577-
expect(result3).toEqual(mockUserImx.profile);
578-
579-
// AuthManager.login should only be called once despite multiple login calls
580-
expect(authLoginMock).toBeCalledTimes(1);
581-
});
582-
583-
it('should reset login promise after successful completion and allow new login calls', async () => {
584-
getUserMock.mockReturnValue(null);
585-
authLoginMock.mockReturnValue(mockUserImx);
586-
587-
// First login call
588-
const firstLoginResult = await passport.login();
589-
expect(firstLoginResult).toEqual(mockUserImx.profile);
590-
591-
// Second login call after first completes should create a new login process
592-
const secondLoginResult = await passport.login();
593-
expect(secondLoginResult).toEqual(mockUserImx.profile);
594-
595-
// AuthManager.login should be called twice (once for each login)
596-
expect(authLoginMock).toBeCalledTimes(2);
597-
});
598-
599-
it('should reset login promise after failed completion and allow new login calls', async () => {
600-
const error = new Error('Login failed');
601-
getUserMock.mockReturnValue(null);
602-
authLoginMock.mockRejectedValue(error);
603-
604-
// First login call should fail
605-
await expect(passport.login()).rejects.toThrow(error);
606-
607-
// Second login call after first fails should create a new login process
608-
authLoginMock.mockReturnValue(mockUserImx);
609-
const secondLoginResult = await passport.login();
610-
expect(secondLoginResult).toEqual(mockUserImx.profile);
611-
612-
// AuthManager.login should be called twice (once for failed, once for successful)
613-
expect(authLoginMock).toBeCalledTimes(2);
614-
});
615-
616-
it('should debounce concurrent login calls even when they fail', async () => {
617-
const error = new Error('Login failed');
618-
getUserMock.mockReturnValue(null);
619-
authLoginMock.mockRejectedValue(error);
620-
621-
// Make multiple concurrent login calls that will fail
622-
const [loginPromise1, loginPromise2, loginPromise3] = [
623-
passport.login(),
624-
passport.login(),
625-
passport.login(),
626-
];
627-
628-
// All promises should be the same reference
629-
expect(loginPromise1).toEqual(loginPromise2);
630-
expect(loginPromise2).toEqual(loginPromise3);
631-
632-
// All should reject with the same error
633-
try {
634-
await Promise.all([loginPromise1, loginPromise2, loginPromise3]);
635-
} catch (e: unknown) {
636-
expect(e).toEqual(error);
637-
// AuthManager.login should only be called once despite multiple login calls
638-
expect(authLoginMock).toBeCalledTimes(1);
639-
}
640-
});
641553
});
642554

643555
describe('linkExternalWallet', () => {

packages/passport/sdk/src/Passport.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ export class Passport {
182182
}, 'connectEvm', false);
183183
}
184184

185-
#loginPromise: Promise<UserProfile | null> | null = null;
186-
187185
/**
188186
* Initiates the login process.
189187
* @param {Object} options - Login options
@@ -207,13 +205,7 @@ export class Passport {
207205
useRedirectFlow?: boolean;
208206
directLoginOptions?: DirectLoginOptions;
209207
}): Promise<UserProfile | null> {
210-
// If there's already a login in progress, return that promise
211-
if (this.#loginPromise) {
212-
return this.#loginPromise;
213-
}
214-
215-
// Create and store the login promise
216-
this.#loginPromise = withMetricsAsync(async () => {
208+
return withMetricsAsync(async () => {
217209
const { useCachedSession = false, useSilentLogin } = options || {};
218210
let user: User | null = null;
219211

@@ -248,14 +240,6 @@ export class Passport {
248240

249241
return user ? user.profile : null;
250242
}, 'login');
251-
252-
try {
253-
const result = await this.#loginPromise;
254-
return result;
255-
} finally {
256-
// Reset the login promise when the login process completes
257-
this.#loginPromise = null;
258-
}
259243
}
260244

261245
/**

0 commit comments

Comments
 (0)