-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1255 from buttercup/fix/password_prompt
Password prompt rebuild
- Loading branch information
Showing
19 changed files
with
375 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import { VaultSourceID } from "buttercup"; | ||
import { getPasswordEmitter } from "../services/password"; | ||
import { sourceHasBiometricAvailability } from "../services/biometrics"; | ||
import { setBiometricSourceID, showPasswordPrompt } from "../state/password"; | ||
import { PASSWORD_STATE } from "../state/password"; | ||
|
||
export async function getPrimaryPassword(sourceID?: VaultSourceID): Promise<string | null> { | ||
export async function getPrimaryPassword( | ||
sourceID?: VaultSourceID | ||
): Promise<[password: string | null, biometricsEnabled: boolean, usedBiometrics: boolean]> { | ||
let biometricsEnabled: boolean = false; | ||
if (sourceID) { | ||
const supportsBiometrics = await sourceHasBiometricAvailability(sourceID); | ||
if (supportsBiometrics) { | ||
setBiometricSourceID(sourceID); | ||
PASSWORD_STATE.passwordViaBiometricSource = sourceID; | ||
biometricsEnabled = true; | ||
} | ||
} | ||
showPasswordPrompt(true); | ||
PASSWORD_STATE.showPrompt = true; | ||
const emitter = getPasswordEmitter(); | ||
const password = await new Promise<string | null>((resolve) => { | ||
const callback = (password: string | null) => { | ||
resolve(password); | ||
const [password, usedBiometrics] = await new Promise<[string | null, boolean]>((resolve) => { | ||
const callback = (password: string | null, usedBiometrics: boolean) => { | ||
resolve([password, usedBiometrics]); | ||
emitter.removeListener("password", callback); | ||
}; | ||
emitter.once("password", callback); | ||
}); | ||
setBiometricSourceID(null); | ||
return password; | ||
PASSWORD_STATE.passwordViaBiometricSource = null; | ||
return [password, biometricsEnabled, usedBiometrics]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.