Skip to content

Commit 1ba6535

Browse files
committed
sign out if revoking current device
1 parent f92dbea commit 1ba6535

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/libs/actions/User.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {getDeviceInfoWithID} from './Device';
6666
import {openOldDotLink} from './Link';
6767
import {showReportActionNotification} from './Report';
6868
import {resendValidateCode as sessionResendValidateCode} from './Session';
69+
import redirectToSignIn from './SignInRedirect';
6970

7071
type DomainOnyxUpdate =
7172
| OnyxUpdate<`${typeof ONYXKEYS.COLLECTION.DOMAIN}${string}`>
@@ -81,7 +82,11 @@ type LockAccountOnyxKey =
8182
| `${typeof ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS}${string}`
8283
| `${typeof ONYXKEYS.COLLECTION.DOMAIN_ERRORS}${string}`;
8384

84-
function revokeDevice(login: NewLogin) {
85+
function revokeDevice(login: NewLogin, autoGeneratedLogin: string | undefined) {
86+
if (!autoGeneratedLogin) {
87+
return;
88+
}
89+
8590
const loginKey = getLoginKey(login);
8691
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.LOGINS>> = [
8792
{
@@ -124,6 +129,11 @@ function revokeDevice(login: NewLogin) {
124129
optimisticData,
125130
successData,
126131
failureData,
132+
}).then(() => {
133+
if (login.partnerUserID !== autoGeneratedLogin) {
134+
return;
135+
}
136+
redirectToSignIn();
127137
});
128138
}
129139

src/pages/settings/Security/DeviceManagementPage.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {FlashList} from '@shopify/flash-list';
22
import type {ListRenderItemInfo} from '@shopify/flash-list';
33
import React from 'react';
44
import {View} from 'react-native';
5+
import type {OnyxEntry} from 'react-native-onyx';
56
import Button from '@components/Button';
67
import HeaderWithBackButton from '@components/HeaderWithBackButton';
78
import OfflineWithFeedback from '@components/OfflineWithFeedback';
@@ -14,13 +15,19 @@ import {clearRevokeError, revokeDevice} from '@libs/actions/User';
1415
import Navigation from '@libs/Navigation/Navigation';
1516
import {getDeviceLogins, getLastLogin, getLoginKey} from '@libs/UserUtils';
1617
import ONYXKEYS from '@src/ONYXKEYS';
18+
import type {Credentials} from '@src/types/onyx';
1719
import type {Login} from '@src/types/onyx/Logins';
1820

21+
function autoGeneratedLoginSelector(credentials: OnyxEntry<Credentials>) {
22+
return credentials?.autoGeneratedLogin;
23+
}
24+
1925
function DeviceManagementPage() {
2026
const styles = useThemeStyles();
2127
const {translate, datetimeToRelative} = useLocalize();
2228

2329
const [logins] = useOnyx(ONYXKEYS.LOGINS, {selector: getDeviceLogins});
30+
const [autoGeneratedLogin] = useOnyx(ONYXKEYS.CREDENTIALS, {selector: autoGeneratedLoginSelector});
2431

2532
const renderItem = ({item}: ListRenderItemInfo<Login>) => {
2633
const {deviceName, deviceVersion, os, osVersion} = item.additionalData ?? {};
@@ -39,7 +46,7 @@ function DeviceManagementPage() {
3946
danger
4047
small
4148
text={translate('deviceManagementPage.revoke')}
42-
onPress={() => revokeDevice(item)}
49+
onPress={() => revokeDevice(item, autoGeneratedLogin)}
4350
/>
4451
</OfflineWithFeedback>
4552
);

0 commit comments

Comments
 (0)