Skip to content

Commit

Permalink
fix: desktop setPassword error (#2347)
Browse files Browse the repository at this point in the history
Co-authored-by: loatheb <18140164+loatheb@users.noreply.github.com>
  • Loading branch information
kwoktung and loatheb authored Jan 4, 2023
1 parent df68fe0 commit 73b577f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/desktop/src-electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ let keytar = {
console.error('keytar.getPassword() not working.');
return Promise.resolve('');
},
async deletePassword(...args: any[]) {
console.error('keytar.deletePassword() not working.');
return Promise.resolve('');
},
};

try {
Expand Down Expand Up @@ -45,6 +49,7 @@ export type DesktopAPI = {
promptTouchID: (msg: string) => Promise<{ success: boolean; error?: string }>;
secureSetItemAsync: (key: string, value: string) => Promise<void>;
secureGetItemAsync: (key: string) => Promise<string | null>;
secureDelItemAsync: (key: string) => Promise<string | null>;
reloadBridgeProcess: () => void;
addIpcEventListener: (
event: string,
Expand Down Expand Up @@ -151,6 +156,9 @@ const desktopApi = {
secureGetItemAsync(key: string) {
return keytar.getPassword('OneKey', key);
},
secureDelItemAsync(key: string) {
return keytar.deletePassword('OneKey', key);
},
reloadBridgeProcess: () => {
ipcRenderer.send('app/reloadBridgeProcess');
},
Expand Down
9 changes: 7 additions & 2 deletions packages/kit/src/utils/localAuthentication.desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ export const localAuthenticate: () => Promise<LocalAuthenticationResult> =
}
};

export const savePassword = (password: string) =>
window?.desktopApi.secureSetItemAsync('password', password);
export const savePassword = (password: string) => {
if (password) {
window?.desktopApi.secureSetItemAsync('password', password);
} else {
window?.desktopApi.secureDelItemAsync('password');
}
};

export const getPassword = () =>
window?.desktopApi.secureGetItemAsync('password');

0 comments on commit 73b577f

Please sign in to comment.