Skip to content

Commit

Permalink
feat: handleBiometricAuth returns result
Browse files Browse the repository at this point in the history
  • Loading branch information
jimcase committed May 8, 2024
1 parent d1d707c commit 9986555
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/ui/components/AppWrapper/hooks/useActivityTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { useEffect, useRef, useState } from "react";
import { App } from "@capacitor/app";
import { useAppDispatch } from "../../../../store/hooks";
import { logout } from "../../../../store/reducers/stateCache";
import { useBiometricAuth } from "../../../hooks/useBiometrics";

const timeout = process.env.NODE_ENV === "development" ? 6000 : 60000; //3600000 1h/1min
const timeout = process.env.NODE_ENV === "development" ? 3600000 : 60000; //3600000 1h/1min
const pauseTimeout = timeout / 2;
const useActivityTimer = () => {
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -59,13 +58,13 @@ const useActivityTimer = () => {
"keydown",
"scroll",
];
events.forEach((event) => {
window.addEventListener(event, handleActivity);
events.forEach(async (event) => {
await window.addEventListener(event, handleActivity);
});

return () => {
events.forEach((event) => {
window.removeEventListener(event, handleActivity);
events.forEach(async (event) => {
await window.removeEventListener(event, handleActivity);
});
clearTimer();
};
Expand Down
6 changes: 4 additions & 2 deletions src/ui/hooks/useBiometrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const useBiometricAuth = () => {
//checkBiometry();
}, []);

const handleBiometricAuth = async () => {
const handleBiometricAuth = async (): Promise<
boolean | BiometryError | undefined
> => {
const biometricResult = await checkBiometry();
if (!biometricResult?.isAvailable) {
if (biometricResult?.strongReason?.includes("NSFaceIDUsageDescription")) {
Expand All @@ -49,7 +51,7 @@ const useBiometricAuth = () => {
androidConfirmationRequired: false,
});
setPauseTimestamp(new Date().getTime());
dispatch(login());
return true;
} catch (error) {
if (
error instanceof BiometryError &&
Expand Down
5 changes: 4 additions & 1 deletion src/ui/pages/LockPage/LockPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ const LockPage = () => {
};

const handleBiometrics = async () => {
handleBiometricAuth();
const isAuthenticated = await handleBiometricAuth();
if (isAuthenticated === true) {
dispatch(login());
}
};
const resetPasscode = () => {
SecureStorage.delete(KeyStoreKeys.APP_PASSCODE).then(() => {
Expand Down

0 comments on commit 9986555

Please sign in to comment.