FAIRE ATTENTION A FIREBASE_CONFIG.JS

This commit is contained in:
tuanvu
2025-11-06 17:14:16 +01:00
parent 2ed5998119
commit aba59680b3
4 changed files with 156 additions and 11 deletions

76
app/login/login.tsx Normal file
View File

@@ -0,0 +1,76 @@
import React, { useState } from "react";
import { View, Text, TextInput, Button, StyleSheet } from "react-native";
import {
signInWithEmailAndPassword,
createUserWithEmailAndPassword,
} from "firebase/auth";
import { doc, setDoc } from "firebase/firestore";
import { auth, db } from "../../firebase_config";
import { router } from "expo-router";
const DEFAULT_ROLE = "resp";
const LoginScreen: React.FC = () => {
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
const handleLogin = async () => {
try {
await signInWithEmailAndPassword(auth, email, password);
router.replace("/(tabs)");
} catch (error: any) {
alert(error.message);
}
};
const handleRegister = async () => {
try {
await createUserWithEmailAndPassword(auth, email, password);
router.replace("/(tabs)");
} catch (error: any) {
alert(error.message);
}
};
return (
<View style={styles.container}>
<Text style={styles.title}>Se connecter / S'incrire</Text>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={setEmail}
autoCapitalize="none"
/>
<TextInput
style={styles.input}
placeholder="Mot de passe"
value={password}
onChangeText={setPassword}
secureTextEntry
/>
<Button title="Se connecter" onPress={handleLogin} />
<View style={{ height: 10 }} />
<Button title="S'incrire" onPress={handleRegister} />
</View>
);
};
export default LoginScreen;
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: "center", padding: 20 },
title: {
fontSize: 22,
fontWeight: "bold",
marginBottom: 20,
textAlign: "center",
},
input: {
borderWidth: 1,
borderColor: "#ccc",
borderRadius: 8,
padding: 10,
marginBottom: 10,
},
});