This commit is contained in:
Bastien COIGNOUX
2026-05-03 20:18:33 +02:00
parent ffc2e6b895
commit bd325fe456
113 changed files with 29532 additions and 220 deletions

95
app/auth/login.tsx Normal file
View File

@ -0,0 +1,95 @@
import { router } from 'expo-router';
import { useState } from 'react';
import {
KeyboardAvoidingView,
Platform,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { LabeledField } from '../../src/components/LabeledField';
import { PrimaryButton } from '../../src/components/PrimaryButton';
import { useApp } from '../../src/context/AppContext';
import { colors } from '../../src/theme/colors';
export default function LoginScreen() {
const insets = useSafeAreaInsets();
const app = useApp();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [err, setErr] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
if (app.runtimeMode !== 'cloud' || !app.supabase) {
return (
<View style={[styles.box, { paddingTop: insets.top }]}>
<Text style={styles.err}>
Configurez dabord Supabase dans Réglages, puis revenez ici.
</Text>
<PrimaryButton
title="Ouvrir Réglages"
onPress={() => router.replace('/(tabs)/reglages')}
/>
</View>
);
}
return (
<KeyboardAvoidingView
style={{ flex: 1, backgroundColor: colors.bg }}
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
>
<ScrollView
keyboardShouldPersistTaps="handled"
contentContainerStyle={{
padding: 20,
paddingTop: insets.top + 12,
paddingBottom: insets.bottom + 24,
}}
>
<LabeledField
label="E-mail"
autoCapitalize="none"
keyboardType="email-address"
value={email}
onChangeText={setEmail}
/>
<LabeledField
label="Mot de passe"
secureTextEntry
value={password}
onChangeText={setPassword}
/>
{err ? <Text style={styles.err}>{err}</Text> : null}
<PrimaryButton
title="Connexion"
loading={loading}
onPress={async () => {
setErr(null);
setLoading(true);
const r = await app.signIn(email.trim(), password);
setLoading(false);
if (r.error) {
setErr(r.error);
return;
}
router.replace('/(tabs)');
}}
/>
<PrimaryButton
title="Créer un compte"
variant="ghost"
onPress={() => router.push('/auth/register')}
containerStyle={{ marginTop: 12 }}
/>
</ScrollView>
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
box: { flex: 1, padding: 20, backgroundColor: colors.bg, gap: 12 },
err: { color: colors.danger, marginBottom: 12 },
});

103
app/auth/register.tsx Normal file
View File

@ -0,0 +1,103 @@
import { router } from 'expo-router';
import { useState } from 'react';
import {
KeyboardAvoidingView,
Platform,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { LabeledField } from '../../src/components/LabeledField';
import { PrimaryButton } from '../../src/components/PrimaryButton';
import { useApp } from '../../src/context/AppContext';
import { colors } from '../../src/theme/colors';
export default function RegisterScreen() {
const insets = useSafeAreaInsets();
const app = useApp();
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [err, setErr] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [info, setInfo] = useState<string | null>(null);
if (app.runtimeMode !== 'cloud' || !app.supabase) {
return (
<View style={[styles.box, { paddingTop: insets.top }]}>
<Text style={styles.err}>
Configurez dabord Supabase dans Réglages.
</Text>
<PrimaryButton
title="Ouvrir Réglages"
onPress={() => router.replace('/(tabs)/reglages')}
/>
</View>
);
}
return (
<KeyboardAvoidingView
style={{ flex: 1, backgroundColor: colors.bg }}
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
>
<ScrollView
keyboardShouldPersistTaps="handled"
contentContainerStyle={{
padding: 20,
paddingTop: insets.top + 12,
paddingBottom: insets.bottom + 24,
}}
>
<LabeledField label="Nom affiché" value={name} onChangeText={setName} />
<LabeledField
label="E-mail"
autoCapitalize="none"
keyboardType="email-address"
value={email}
onChangeText={setEmail}
/>
<LabeledField
label="Mot de passe"
secureTextEntry
value={password}
onChangeText={setPassword}
/>
{err ? <Text style={styles.err}>{err}</Text> : null}
{info ? <Text style={styles.info}>{info}</Text> : null}
<PrimaryButton
title="Sinscrire"
loading={loading}
onPress={async () => {
setErr(null);
setInfo(null);
setLoading(true);
const r = await app.signUp(email.trim(), password, name.trim());
setLoading(false);
if (r.error) {
setErr(r.error);
return;
}
setInfo(
'Si la confirmation e-mail est activée sur votre projet, vérifiez votre boîte avant de vous connecter.',
);
}}
/>
<PrimaryButton
title="Jai déjà un compte"
variant="ghost"
onPress={() => router.back()}
containerStyle={{ marginTop: 12 }}
/>
</ScrollView>
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
box: { flex: 1, padding: 20, backgroundColor: colors.bg, gap: 12 },
err: { color: colors.danger, marginBottom: 12 },
info: { color: colors.flash, marginBottom: 12, lineHeight: 20 },
});