Skip to content

Commit

Permalink
Deactivate device upon logout (#137)
Browse files Browse the repository at this point in the history
Fix a legacy behaviour where deactivate device was not yet implemented.
Devices are now deactivated upon logout.

Fix #133
  • Loading branch information
Mikescops authored Aug 2, 2023
1 parent fcdccb2 commit 86ac92b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Database } from 'better-sqlite3';
import { connectAndPrepare } from './database/index';
import { askConfirmReset } from './utils/dialogs';
import { getTeamDeviceCredentialsFromEnv, parseBooleanString } from './utils';
import { Secrets } from './types';
import { DeviceConfiguration, Secrets } from './types';
import { connect } from './database/connect';
import {
sync,
Expand All @@ -25,6 +25,7 @@ import { registerTeamDevice } from './endpoints/registerTeamDevice';
import { listAllDevices, removeAllDevices, listAllTeamDevices } from './command-handlers';
import { deactivateTeamDevice } from './endpoints/deactivateTeamDevice';
import { CouldNotFindTeamCredentialsError } from './errors';
import { deactivateDevices } from './endpoints';

const teamDeviceCredentials = getTeamDeviceCredentialsFromEnv();

Expand Down Expand Up @@ -286,8 +287,9 @@ program
if (resetConfirmation) {
let db: Database;
let secrets: Secrets | undefined;
let deviceConfiguration: DeviceConfiguration | null | undefined;
try {
({ db, secrets } = await connectAndPrepare({ autoSync: false, failIfNoDB: true }));
({ db, secrets, deviceConfiguration } = await connectAndPrepare({ autoSync: false, failIfNoDB: true }));
} catch (error) {
let errorMessage = 'unknown error';
if (error instanceof Error) {
Expand All @@ -298,6 +300,13 @@ program
db = connect();
db.serialize();
}
if (secrets && deviceConfiguration) {
await deactivateDevices({
deviceIds: [deviceConfiguration.accessKey],
login: deviceConfiguration.login,
secrets,
});
}
reset({ db, secrets });
console.log('The local Dashlane local storage has been reset and you have been logged out');
db.close();
Expand Down

0 comments on commit 86ac92b

Please sign in to comment.