-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.tsx
More file actions
42 lines (42 loc) · 1.5 KB
/
fetch.tsx
File metadata and controls
42 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
try {
const dbRef = ref(db);
const snapshot = await get(child(dbRef, `User`));
if (snapshot.exists()) {
const users = snapshot.val();
for (const userId in users) {
if (
users[userId].email === email &&
users[userId].password === password
) {
if (users[userId].status === 'enable') {
setLoading(false);
Alert.alert('Connexion réussie', 'Connecté avec succès');
onLoginSuccess(email);
ident.setEmail(email);
ident.setpassword(password);
ident.setname(users[userId].name);
console.log("Voici le nom : " , users[userId].name);
return;
} else {
setLoading(false);
Alert.alert('Connexion échouée', 'Votre compte est désactivé, contactez un administrateur.');
return;
}
}
}
setLoading(false);
Alert.alert('Login Failed', 'Invalid email or password.');
} else {
setLoading(false);
Alert.alert('Login Failed', 'No users found.');
}
} catch (error: any) {
setLoading(false);
if (error.message.includes('Network request failed')) {
Alert.alert('Network Error', 'Unable to connect to the internet. Please check your connection and try again.');
} else {
Alert.alert('Login Failed', 'Error connecting to the database.');
}
console.error(error);
}
};