168 lines
4.1 KiB
TypeScript
168 lines
4.1 KiB
TypeScript
import { useState } from 'react';
|
|
import { View, Text, Pressable, StyleSheet, ActivityIndicator } from 'react-native';
|
|
import { useRouter } from 'expo-router';
|
|
import { useAuthStore } from '@/store/auth';
|
|
import { authClient } from '@/lib/auth-client';
|
|
|
|
/**
|
|
* Passkey registration prompt
|
|
* Post-signup, allows user to optionally register a passkey (WebAuthn)
|
|
* This screen is skippable
|
|
*/
|
|
export default function PasskeyPromptScreen() {
|
|
const router = useRouter();
|
|
const { user } = useAuthStore();
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [error, setError] = useState('');
|
|
|
|
const handleAddPasskey = async () => {
|
|
if (!user) return;
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
setError('');
|
|
await authClient.passkey.addPasskey();
|
|
// After passkey is added, go to household setup
|
|
router.replace('/(auth)/household');
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : 'Failed to register passkey';
|
|
setError(message);
|
|
console.error('Passkey registration error:', err);
|
|
// Even if passkey fails, let user continue
|
|
setTimeout(() => {
|
|
router.replace('/(auth)/household');
|
|
}, 2000);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const handleSkip = () => {
|
|
router.replace('/(auth)/household');
|
|
};
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.content}>
|
|
<Text style={styles.icon}>🔐</Text>
|
|
<Text style={styles.title}>Secure Your Account</Text>
|
|
<Text style={styles.subtitle}>
|
|
Set up a passkey to sign in faster and more securely, without remembering passwords.
|
|
</Text>
|
|
|
|
{error && <Text style={styles.error}>{error}</Text>}
|
|
|
|
<Pressable
|
|
style={[styles.button, styles.primaryButton]}
|
|
onPress={handleAddPasskey}
|
|
disabled={isLoading}
|
|
>
|
|
{isLoading ? (
|
|
<ActivityIndicator color="#fff" />
|
|
) : (
|
|
<Text style={styles.buttonText}>Add Passkey</Text>
|
|
)}
|
|
</Pressable>
|
|
|
|
<Pressable style={styles.secondaryButton} onPress={handleSkip} disabled={isLoading}>
|
|
<Text style={styles.secondaryButtonText}>Skip for Now</Text>
|
|
</Pressable>
|
|
|
|
<View style={styles.infoBox}>
|
|
<Text style={styles.infoTitle}>What's a Passkey?</Text>
|
|
<Text style={styles.infoText}>
|
|
A passkey is a secure way to sign in using your device's face or fingerprint. It's
|
|
faster and more secure than passwords.
|
|
</Text>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: '#fff',
|
|
justifyContent: 'center',
|
|
},
|
|
content: {
|
|
paddingHorizontal: 20,
|
|
paddingVertical: 40,
|
|
},
|
|
icon: {
|
|
fontSize: 60,
|
|
textAlign: 'center',
|
|
marginBottom: 20,
|
|
},
|
|
title: {
|
|
fontSize: 28,
|
|
fontWeight: 'bold',
|
|
textAlign: 'center',
|
|
marginBottom: 12,
|
|
},
|
|
subtitle: {
|
|
fontSize: 16,
|
|
color: '#666',
|
|
textAlign: 'center',
|
|
marginBottom: 32,
|
|
lineHeight: 24,
|
|
},
|
|
button: {
|
|
paddingVertical: 12,
|
|
paddingHorizontal: 24,
|
|
borderRadius: 8,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
marginVertical: 8,
|
|
},
|
|
primaryButton: {
|
|
backgroundColor: '#007AFF',
|
|
},
|
|
buttonText: {
|
|
color: '#fff',
|
|
fontSize: 16,
|
|
fontWeight: '600',
|
|
},
|
|
secondaryButton: {
|
|
borderWidth: 1,
|
|
borderColor: '#ddd',
|
|
paddingVertical: 12,
|
|
paddingHorizontal: 24,
|
|
borderRadius: 8,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
marginVertical: 8,
|
|
},
|
|
secondaryButtonText: {
|
|
color: '#333',
|
|
fontSize: 16,
|
|
fontWeight: '600',
|
|
},
|
|
infoBox: {
|
|
backgroundColor: '#f0f8ff',
|
|
padding: 16,
|
|
borderRadius: 8,
|
|
marginTop: 32,
|
|
},
|
|
infoTitle: {
|
|
fontSize: 14,
|
|
fontWeight: '600',
|
|
color: '#007AFF',
|
|
marginBottom: 8,
|
|
},
|
|
infoText: {
|
|
fontSize: 14,
|
|
color: '#333',
|
|
lineHeight: 20,
|
|
},
|
|
error: {
|
|
color: '#ff3333',
|
|
fontSize: 14,
|
|
marginBottom: 12,
|
|
textAlign: 'center',
|
|
padding: 12,
|
|
backgroundColor: '#ffe5e5',
|
|
borderRadius: 6,
|
|
},
|
|
});
|