MOBILE-4606 login: Fix loginSuccessful calculation when authenticating
parent
3d393e7bdc
commit
e666fdc517
|
@ -80,10 +80,16 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
protected urlToOpen?: string;
|
||||
protected valueChangeSubscription?: Subscription;
|
||||
protected alwaysShowLoginFormObserver?: CoreEventObserver;
|
||||
protected loginObserver?: CoreEventObserver;
|
||||
|
||||
constructor(
|
||||
protected fb: FormBuilder,
|
||||
) {}
|
||||
) {
|
||||
// Listen to LOGIN event to determine if login was successful, since the login can be done using QR, SSO, etc.
|
||||
this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, ({ siteId }) => {
|
||||
this.siteId = siteId;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
@ -297,14 +303,12 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
try {
|
||||
const data = await CoreSites.getUserToken(siteUrl, username, password);
|
||||
|
||||
const id = await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
|
||||
await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
|
||||
|
||||
// Reset fields so the data is not in the view anymore.
|
||||
this.credForm.controls['username'].reset();
|
||||
this.credForm.controls['password'].reset();
|
||||
|
||||
this.siteId = id;
|
||||
|
||||
await CoreNavigator.navigateToSiteHome({ params: { urlToOpen: this.urlToOpen } });
|
||||
} catch (error) {
|
||||
if (error instanceof CoreSiteError && CoreLoginHelper.isAppUnsupportedError(error)) {
|
||||
|
@ -379,6 +383,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
);
|
||||
this.valueChangeSubscription?.unsubscribe();
|
||||
this.alwaysShowLoginFormObserver?.off();
|
||||
this.loginObserver?.off();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
protected loginSuccessful = false;
|
||||
protected username = '';
|
||||
protected alwaysShowLoginFormObserver?: CoreEventObserver;
|
||||
protected loginObserver?: CoreEventObserver;
|
||||
|
||||
constructor(
|
||||
protected fb: FormBuilder,
|
||||
|
@ -81,6 +82,11 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
this.credForm = fb.group({
|
||||
password: ['', Validators.required],
|
||||
});
|
||||
|
||||
// Listen to LOGIN event to determine if login was successful, since the login can be done using QR, biometric, etc.
|
||||
this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, () => {
|
||||
this.loginSuccessful = true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,6 +162,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
this.siteId,
|
||||
);
|
||||
this.alwaysShowLoginFormObserver?.off();
|
||||
this.loginObserver?.off();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,8 +269,6 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
this.credForm.controls['password'].reset();
|
||||
|
||||
// Go to the site initial page.
|
||||
this.loginSuccessful = true;
|
||||
|
||||
await CoreNavigator.navigateToSiteHome({
|
||||
params: this.redirectData,
|
||||
});
|
||||
|
|
|
@ -1443,7 +1443,7 @@ export class CoreSitesProvider {
|
|||
async login(siteId: string): Promise<void> {
|
||||
await CoreConfig.set(CORE_SITE_CURRENT_SITE_ID_CONFIG, siteId);
|
||||
|
||||
CoreEvents.trigger(CoreEvents.LOGIN, {}, siteId);
|
||||
CoreEvents.trigger(CoreEvents.LOGIN, { siteId }, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,7 +72,7 @@ describe('CoreSitesProvider', () => {
|
|||
getCurrentSiteId: () => '42',
|
||||
});
|
||||
|
||||
CoreEvents.trigger(CoreEvents.LOGIN, {}, '42');
|
||||
CoreEvents.trigger(CoreEvents.LOGIN, { siteId: '42' }, '42');
|
||||
// Wait the event to be processed.
|
||||
await CoreWait.nextTick();
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ export interface CoreEventsData {
|
|||
[CoreEvents.IAB_LOAD_START]: InAppBrowserEvent;
|
||||
[CoreEvents.IAB_LOAD_STOP]: InAppBrowserEvent;
|
||||
[CoreEvents.IAB_MESSAGE]: Record<string, unknown>;
|
||||
[CoreEvents.LOGIN]: { siteId: string };
|
||||
[CoreEvents.LOGIN_SITE_CHECKED]: CoreEventLoginSiteCheckedData;
|
||||
[CoreEvents.LOGIN_SITE_UNCHECKED]: CoreEventLoginSiteUncheckedData;
|
||||
[CoreEvents.SEND_ON_ENTER_CHANGED]: CoreEventSendOnEnterChangedData;
|
||||
|
|
Loading…
Reference in New Issue