Skip to content

Commit

Permalink
Use dynamic import for auth.node
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikescops committed Mar 29, 2024
1 parent 30a5c4f commit d7cdc6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"node_modules/@json2csv/plainjs/dist/**/*",
"node_modules/@json2csv/formatters/dist/**/*",
"node_modules/@json2csv/transforms/dist/**/*",
"node_modules/@streamparser/json/dist/**/*"
"node_modules/@streamparser/json/dist/**/*",
"node_modules/node-mac-auth/build/Release/auth.node"
]
},
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions src/command-handlers/configure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import winston from 'winston';
import { canPromptTouchID } from 'node-mac-auth';
import { encryptAesCbcHmac256 } from '../modules/crypto/encrypt';
import { deleteLocalKey, setLocalKey, warnUnreachableKeychainDisabled } from '../modules/crypto/keychainManager';
import { connectAndPrepare } from '../modules/database';
Expand Down Expand Up @@ -71,8 +70,13 @@ export const configureUserPresenceVerification = async (options: {
const { method } = options;
const { db, localConfiguration } = await connectAndPrepare({ autoSync: false });

if (method === 'biometrics' && !canPromptTouchID()) {
throw new Error('Biometrics are not supported on your device.');
if (method === 'biometrics') {
if (process.platform === 'darwin') {
const { canPromptTouchID } = await import('node-mac-auth');
if (!canPromptTouchID()) {
throw new Error('Biometrics are not supported on your device.');
}
}
}

db.prepare('UPDATE device SET userPresenceVerification = ? WHERE login = ?')
Expand Down
20 changes: 11 additions & 9 deletions src/modules/auth/userPresenceVerification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { promptTouchID, canPromptTouchID } from 'node-mac-auth';
import { DeviceConfiguration } from '../../types';

export const userPresenceVerification = async (params: { deviceConfiguration: DeviceConfiguration | null }) => {
Expand All @@ -13,15 +12,18 @@ export const userPresenceVerification = async (params: { deviceConfiguration: De
}

if (deviceConfiguration.userPresenceVerification === 'biometrics') {
if (canPromptTouchID()) {
return promptTouchID({
reason: 'validate your identity before accessing your vault',
reuseDuration: 60, // 1min - dies when program closes
}).catch((error) => {
throw new Error(`Touch ID verification failed: ${error}`);
});
if (process.platform === 'darwin') {
const { canPromptTouchID, promptTouchID } = await import('node-mac-auth');
if (canPromptTouchID()) {
return promptTouchID({
reason: 'validate your identity before accessing your vault',
reuseDuration: 60, // 1min - dies when program closes
}).catch((error) => {
throw new Error(`Touch ID verification failed: ${error}`);
});
}
} else {
throw new Error('Biometrics are not supported on your device.');
throw new Error('Biometrics are only supported on macos for now.');
}
}
};

0 comments on commit d7cdc6e

Please sign in to comment.