From b40008517bd433b69313c9c006a29d8f4ef4302c Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Wed, 9 Nov 2022 14:37:29 -0800 Subject: [PATCH] clear device token on logout --- app/mobile/index.js | 2 -- app/mobile/ios/Databag.xcodeproj/project.pbxproj | 5 +++++ app/mobile/ios/Podfile.lock | 2 +- app/mobile/src/api/clearLogin.js | 7 +++++++ app/mobile/src/context/useAppContext.hook.js | 13 +++++++++++++ app/mobile/src/session/profile/useProfile.hook.js | 4 ++-- doc/api.oa3 | 3 +++ 7 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 app/mobile/src/api/clearLogin.js diff --git a/app/mobile/index.js b/app/mobile/index.js index d6277f79..18095644 100644 --- a/app/mobile/index.js +++ b/app/mobile/index.js @@ -3,8 +3,6 @@ import { registerRootComponent } from 'expo'; import App from './App'; import messaging from '@react-native-firebase/messaging'; -messaging().requestPermission().then(status => {}) - messaging().registerDeviceForRemoteMessages().then(() => {}); messaging().setBackgroundMessageHandler(async remoteMessage => {}); diff --git a/app/mobile/ios/Databag.xcodeproj/project.pbxproj b/app/mobile/ios/Databag.xcodeproj/project.pbxproj index 8d493de1..bfbadc91 100644 --- a/app/mobile/ios/Databag.xcodeproj/project.pbxproj +++ b/app/mobile/ios/Databag.xcodeproj/project.pbxproj @@ -434,6 +434,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; + BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Databag/Databag.entitlements; CURRENT_PROJECT_VERSION = 30; @@ -463,6 +464,7 @@ SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_WORKSPACE = YES; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -471,8 +473,10 @@ isa = XCBuildConfiguration; baseConfigurationReference = 7A4D352CD337FB3A3BF06240 /* Pods-Databag.release.xcconfig */; buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; + BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Databag/Databag.entitlements; CURRENT_PROJECT_VERSION = 30; @@ -496,6 +500,7 @@ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_WORKSPACE = YES; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; diff --git a/app/mobile/ios/Podfile.lock b/app/mobile/ios/Podfile.lock index 2e908c83..e1bdc265 100644 --- a/app/mobile/ios/Podfile.lock +++ b/app/mobile/ios/Podfile.lock @@ -669,7 +669,7 @@ SPEC CHECKSUMS: FirebaseInstallations: 99d24bac0243cf8b0e96cf5426340d211f0bcc80 FirebaseMessaging: 4487bbff9b9b927ba1dd3ea40d1ceb58e4ee3cb5 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 - glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b + glog: 3d02b25ca00c2d456734d0bcff864cbc62f6ae1a GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7 nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431 diff --git a/app/mobile/src/api/clearLogin.js b/app/mobile/src/api/clearLogin.js new file mode 100644 index 00000000..69b6a321 --- /dev/null +++ b/app/mobile/src/api/clearLogin.js @@ -0,0 +1,7 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import base64 from 'react-native-base64' + +export async function clearLogin(server, token) { + let logout = await fetchWithTimeout(`https://${server}/account/apps?agent=${token}`, { method: 'DELETE' }) + checkResponse(logout) +} diff --git a/app/mobile/src/context/useAppContext.hook.js b/app/mobile/src/context/useAppContext.hook.js index e6718017..67043306 100644 --- a/app/mobile/src/context/useAppContext.hook.js +++ b/app/mobile/src/context/useAppContext.hook.js @@ -1,6 +1,7 @@ import { useEffect, useState, useRef, useContext } from 'react'; import { getAvailable } from 'api/getAvailable'; import { setLogin } from 'api/setLogin'; +import { clearLogin } from 'api/clearLogin'; import { removeProfile } from 'api/removeProfile'; import { setAccountAccess } from 'api/setAccountAccess'; import { addAccount } from 'api/addAccount'; @@ -87,10 +88,22 @@ export function useAppContext() { login: async (username, password) => { const acc = username.split('@'); const access = await setLogin(acc[0], acc[1], password, getApplicationName(), getVersion(), getDeviceId(), state.deviceToken, ['contact', 'channel']) + if (access.pushSupported) { + messaging().requestPermission().then(status => {}) + } await store.actions.setSession({ ...access, server: acc[1]}); await setSession({ ...access, server: acc[1] }); }, logout: async () => { + try { + await messaging().deleteToken(); + const token = await messaging().getToken(); + updateState({ deviceToken: token }); + await clearLogin(state.server, state.appToken); + } + catch (err) { + console.log(err); + } await clearSession(); await store.actions.clearSession(); }, diff --git a/app/mobile/src/session/profile/useProfile.hook.js b/app/mobile/src/session/profile/useProfile.hook.js index 5ebe17b9..583ddefc 100644 --- a/app/mobile/src/session/profile/useProfile.hook.js +++ b/app/mobile/src/session/profile/useProfile.hook.js @@ -47,8 +47,8 @@ export function useProfile() { }, [app]); const actions = { - logout: () => { - app.actions.logout(); + logout: async () => { + await app.actions.logout(); navigate('/'); }, remove: async () => { diff --git a/doc/api.oa3 b/doc/api.oa3 index 37d9c259..35335bca 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -3507,6 +3507,7 @@ components: - guid - appToken - created + - pushSupported properties: guid: type: string @@ -3515,6 +3516,8 @@ components: created: type: integer format: int64 + pushSupported: + type: boolean Revision: type: object