Skip to content

Commit

Permalink
chore: add alert in security page
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Sep 17, 2024
1 parent c96d93c commit 8e708e7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default function RootLayout() {

async function checkBiometricStatus() {
const compatible = await LocalAuthentication.hasHardwareAsync();
const enrolled = await LocalAuthentication.isEnrolledAsync();
if (compatible && enrolled) {
const securityLevel = await LocalAuthentication.getEnrolledLevelAsync();
if (compatible && securityLevel > 0) {
useAppStore.getState().setBiometricSupported(true);
} else {
useAppStore.getState().setBiometricSupported(false);
Expand Down
3 changes: 3 additions & 0 deletions components/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
Fingerprint,
HelpCircle,
CircleCheck,
TriangleAlert,
} from "lucide-react-native";
import { cssInterop } from "nativewind";

Expand Down Expand Up @@ -89,6 +90,7 @@ interopIcon(Egg);
interopIcon(Fingerprint);
interopIcon(HelpCircle);
interopIcon(CircleCheck);
interopIcon(TriangleAlert);

export {
AlertCircle,
Expand Down Expand Up @@ -128,4 +130,5 @@ export {
Fingerprint,
HelpCircle,
CircleCheck,
TriangleAlert,
};
17 changes: 16 additions & 1 deletion pages/settings/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,37 @@ import { Label } from "~/components/ui/label";
import { Switch } from "~/components/ui/switch";
import Screen from "~/components/Screen";
import { useAppStore } from "~/lib/state/appStore";
import { TriangleAlert } from "~/components/Icons";
import { cn } from "~/lib/utils";

export function Security() {
const isEnabled = useAppStore((store) => store.isSecurityEnabled);
const isSupported = useAppStore((store) => store.isBiometricSupported);
return (
<View className="flex-1 p-6">
<Screen title="Security" />
{!isSupported && (
<View className="flex-row items-center border border-muted-foreground rounded-lg p-3 mb-4 gap-3">
<TriangleAlert className="text-foreground" />
<View className="flex-col">
<Text className="font-bold text-base">Can't add security</Text>
<Text className="text-sm">
Add phone lock in device settings to secure access
</Text>
</View>
</View>
)}
<View className="flex-1">
<View className='flex-row items-center justify-between gap-2'>
<Label
className="text-2xl"
className={cn('text-2xl', !isSupported && 'opacity-50')}
nativeID='security'
>
<Text className="text-lg">Require phone lock to access</Text>
</Label>
<Switch
checked={isEnabled}
disabled={!isSupported}
onCheckedChange={() => {
useAppStore.getState().setSecurityEnabled(!isEnabled);
}}
Expand Down
18 changes: 8 additions & 10 deletions pages/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ export function Settings() {
</TouchableOpacity>
</Link>

{isBiometricSupported && (
<Link href="/settings/security" asChild>
<TouchableOpacity className="flex flex-row gap-4">
<Fingerprint className="text-foreground" />
<Text className="text-foreground font-medium2 text-xl">
Security
</Text>
</TouchableOpacity>
</Link>
)}
<Link href="/settings/security" asChild>
<TouchableOpacity className="flex flex-row gap-4">
<Fingerprint className="text-foreground" />
<Text className="text-foreground font-medium2 text-xl">
Security
</Text>
</TouchableOpacity>
</Link>

<TouchableOpacity
className="flex flex-row gap-4"
Expand Down

0 comments on commit 8e708e7

Please sign in to comment.