Skip to content

Commit

Permalink
fix: show auth prompt only once
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron authored Oct 30, 2024
1 parent 0e0414d commit 1f5b73a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pages/Unlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as LocalAuthentication from "expo-local-authentication";
import { router, Stack } from "expo-router";
import React from "react";
import React, { useCallback, useEffect } from "react";
import { Image, View } from "react-native";

import { Button } from "~/components/ui/button";
Expand All @@ -11,7 +11,14 @@ export function Unlock() {
const [isUnlocking, setIsUnlocking] = React.useState(false);
const { signIn } = useSession();

const handleUnlock = React.useCallback(async (): Promise<void> => {
const handleUnlock = useCallback(async () => {
// The call `signIn()` below triggers a re-render of the component
// and would prompt the user again (before the actual redirect
// happens and the view is replaced)
if (isUnlocking) {
return;
}

try {
setIsUnlocking(true);
const biometricAuth = await LocalAuthentication.authenticateAsync({
Expand All @@ -26,9 +33,9 @@ export function Unlock() {
} finally {
setIsUnlocking(false);
}
}, [signIn]);
}, [isUnlocking, signIn]);

React.useEffect(() => {
useEffect(() => {
handleUnlock();
}, [handleUnlock]);

Expand Down

0 comments on commit 1f5b73a

Please sign in to comment.