Skip to content

Commit e666fdc

Browse files
committed
MOBILE-4606 login: Fix loginSuccessful calculation when authenticating
1 parent 3d393e7 commit e666fdc

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

src/core/features/login/pages/credentials/credentials.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
8080
protected urlToOpen?: string;
8181
protected valueChangeSubscription?: Subscription;
8282
protected alwaysShowLoginFormObserver?: CoreEventObserver;
83+
protected loginObserver?: CoreEventObserver;
8384

8485
constructor(
8586
protected fb: FormBuilder,
86-
) {}
87+
) {
88+
// Listen to LOGIN event to determine if login was successful, since the login can be done using QR, SSO, etc.
89+
this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, ({ siteId }) => {
90+
this.siteId = siteId;
91+
});
92+
}
8793

8894
/**
8995
* @inheritdoc
@@ -297,14 +303,12 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
297303
try {
298304
const data = await CoreSites.getUserToken(siteUrl, username, password);
299305

300-
const id = await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
306+
await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
301307

302308
// Reset fields so the data is not in the view anymore.
303309
this.credForm.controls['username'].reset();
304310
this.credForm.controls['password'].reset();
305311

306-
this.siteId = id;
307-
308312
await CoreNavigator.navigateToSiteHome({ params: { urlToOpen: this.urlToOpen } });
309313
} catch (error) {
310314
if (error instanceof CoreSiteError && CoreLoginHelper.isAppUnsupportedError(error)) {
@@ -379,6 +383,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
379383
);
380384
this.valueChangeSubscription?.unsubscribe();
381385
this.alwaysShowLoginFormObserver?.off();
386+
this.loginObserver?.off();
382387
}
383388

384389
}

src/core/features/login/pages/reconnect/reconnect.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
7171
protected loginSuccessful = false;
7272
protected username = '';
7373
protected alwaysShowLoginFormObserver?: CoreEventObserver;
74+
protected loginObserver?: CoreEventObserver;
7475

7576
constructor(
7677
protected fb: FormBuilder,
@@ -81,6 +82,11 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
8182
this.credForm = fb.group({
8283
password: ['', Validators.required],
8384
});
85+
86+
// Listen to LOGIN event to determine if login was successful, since the login can be done using QR, biometric, etc.
87+
this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, () => {
88+
this.loginSuccessful = true;
89+
});
8490
}
8591

8692
/**
@@ -156,6 +162,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
156162
this.siteId,
157163
);
158164
this.alwaysShowLoginFormObserver?.off();
165+
this.loginObserver?.off();
159166
}
160167

161168
/**
@@ -262,8 +269,6 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
262269
this.credForm.controls['password'].reset();
263270

264271
// Go to the site initial page.
265-
this.loginSuccessful = true;
266-
267272
await CoreNavigator.navigateToSiteHome({
268273
params: this.redirectData,
269274
});

src/core/services/sites.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ export class CoreSitesProvider {
14431443
async login(siteId: string): Promise<void> {
14441444
await CoreConfig.set(CORE_SITE_CURRENT_SITE_ID_CONFIG, siteId);
14451445

1446-
CoreEvents.trigger(CoreEvents.LOGIN, {}, siteId);
1446+
CoreEvents.trigger(CoreEvents.LOGIN, { siteId }, siteId);
14471447
}
14481448

14491449
/**

src/core/services/tests/sites.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('CoreSitesProvider', () => {
7272
getCurrentSiteId: () => '42',
7373
});
7474

75-
CoreEvents.trigger(CoreEvents.LOGIN, {}, '42');
75+
CoreEvents.trigger(CoreEvents.LOGIN, { siteId: '42' }, '42');
7676
// Wait the event to be processed.
7777
await CoreWait.nextTick();
7878

src/core/singletons/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface CoreEventsData {
5656
[CoreEvents.IAB_LOAD_START]: InAppBrowserEvent;
5757
[CoreEvents.IAB_LOAD_STOP]: InAppBrowserEvent;
5858
[CoreEvents.IAB_MESSAGE]: Record<string, unknown>;
59+
[CoreEvents.LOGIN]: { siteId: string };
5960
[CoreEvents.LOGIN_SITE_CHECKED]: CoreEventLoginSiteCheckedData;
6061
[CoreEvents.LOGIN_SITE_UNCHECKED]: CoreEventLoginSiteUncheckedData;
6162
[CoreEvents.SEND_ON_ENTER_CHANGED]: CoreEventSendOnEnterChangedData;

0 commit comments

Comments
 (0)