diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index b9b9f0191..ea5786eca 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -51,6 +51,11 @@ export enum CoreSiteQRCodeType { QR_CODE_LOGIN = 2, // QR code type login value } +// WS that we allow to call even if the site is logged out. +const ALLOWED_LOGGEDOUT_WS = [ + 'core_user_remove_user_device', +]; + /** * Class that represents a site (combination of site + user). * It will have all the site data and provide utility functions regarding a site. @@ -496,7 +501,7 @@ export class CoreSite { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any async request(method: string, data: any, preSets: CoreSiteWSPreSets, retrying?: boolean): Promise { - if (this.isLoggedOut()) { + if (this.isLoggedOut() && !ALLOWED_LOGGEDOUT_WS.includes(method)) { // Site is logged out, it cannot call WebServices. CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {}, this.id); diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index 9de4396d8..ba07fa9d3 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -519,20 +519,10 @@ export class CorePushNotificationsProvider { appid: CoreConstants.CONFIG.app_id, uuid: Device.uuid, }; + let response: CoreUserRemoveUserDeviceWSResponse; try { - const response = await site.write('core_user_remove_user_device', data); - - if (!response || !response.removed) { - throw new CoreError('Cannot unregister device'); - } - - await CoreUtils.ignoreErrors(Promise.all([ - // Remove the device from the local DB. - site.getDb().deleteRecords(REGISTERED_DEVICES_TABLE_NAME, this.getRegisterData()), - // Remove pending unregisters for this site. - db.deleteRecords(PENDING_UNREGISTER_TABLE_NAME, { siteid: site.getId() }), - ])); + response = await site.write('core_user_remove_user_device', data); } catch (error) { if (CoreUtils.isWebServiceError(error)) { throw error; @@ -546,7 +536,20 @@ export class CorePushNotificationsProvider { info: JSON.stringify(site.getInfo()), }; await db.insertRecord(PENDING_UNREGISTER_TABLE_NAME, entry); + + return; } + + if (!response.removed) { + throw new CoreError('Cannot unregister device'); + } + + await CoreUtils.ignoreErrors(Promise.all([ + // Remove the device from the local DB. + site.getDb().deleteRecords(REGISTERED_DEVICES_TABLE_NAME, this.getRegisterData()), + // Remove pending unregisters for this site. + db.deleteRecords(PENDING_UNREGISTER_TABLE_NAME, { siteid: site.getId() }), + ])); } /**