-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
190 additions
and
84 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// hooks/useBiometricAuth.js | ||
import { useState, useEffect } from "react"; | ||
import { | ||
BiometricAuth, | ||
BiometryError, | ||
BiometryErrorType, | ||
} from "@aparajita/capacitor-biometric-auth"; | ||
import { useDispatch } from "react-redux"; | ||
import { login } from "../../store/reducers/stateCache"; | ||
import { useActivityTimer } from "../components/AppWrapper/hooks/useActivityTimer"; | ||
|
||
const useBiometricAuth = () => { | ||
const [biometricInfo, setBiometricInfo] = useState<any>(); | ||
const dispatch = useDispatch(); | ||
const { setPauseTimestamp } = useActivityTimer(); | ||
|
||
const checkBiometry = async () => { | ||
try { | ||
const biometricResult = await BiometricAuth.checkBiometry(); | ||
setBiometricInfo(biometricResult); | ||
return biometricResult; | ||
} catch (error) { | ||
//console.error('Error checking biometry:', error); | ||
} | ||
}; | ||
useEffect(() => { | ||
//checkBiometry(); | ||
}, []); | ||
|
||
const handleBiometricAuth = async () => { | ||
const biometricResult = await checkBiometry(); | ||
if (!biometricResult?.isAvailable) { | ||
if (biometricResult?.strongReason?.includes("NSFaceIDUsageDescription")) { | ||
alert( | ||
"Please enable Face ID in your device settings or update the app for enhanced security." | ||
); | ||
} | ||
return; | ||
} | ||
|
||
try { | ||
await BiometricAuth.authenticate({ | ||
reason: "Please authenticate", | ||
cancelTitle: "Cancel", | ||
allowDeviceCredential: true, | ||
iosFallbackTitle: "Use passcode", | ||
androidTitle: "Biometric login", | ||
androidSubtitle: "Log in using biometric authentication", | ||
androidConfirmationRequired: false, | ||
}); | ||
setPauseTimestamp(new Date().getTime()); | ||
dispatch(login()); | ||
} catch (error) { | ||
if ( | ||
error instanceof BiometryError && | ||
error.code !== BiometryErrorType.userCancel | ||
) { | ||
// Handle other biometry errors here | ||
//console.error('Biometry Error:', error.message); | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
biometricInfo, | ||
handleBiometricAuth, | ||
}; | ||
}; | ||
|
||
export { useBiometricAuth }; |
Oops, something went wrong.