-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForgotPassword.js
84 lines (80 loc) · 1.85 KB
/
ForgotPassword.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { useState } from "react";
import {
View,
Text,
TextInput,
TouchableOpacity,
StyleSheet,
} from "react-native";
import { getAuth, sendPasswordResetEmail } from "firebase/auth";
export default function ForgotPassword({ userEmail }) {
const [email, setEmail] = useState(userEmail);
const [message, setMessage] = useState("");
const handleForgotPassword = () => {
const auth = getAuth();
if (auth) {
sendPasswordResetEmail(auth, email)
.then(() => {
setMessage("Request password reset email sent!");
})
.catch((error) => {
setMessage(error.message);
});
} else {
setMessage("Authentication service is not available.");
}
};
return (
<View style={styles.container}>
<Text style={styles.header}>Forgot Password</Text>
<TextInput
style={styles.input}
placeholder="Enter your email"
value={email}
onChangeText={(text) => setEmail(text)}
/>
<TouchableOpacity style={styles.button} onPress={handleForgotPassword}>
<Text style={styles.buttonText}>Reset Password</Text>
</TouchableOpacity>
<Text style={styles.message}>{message}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
header: {
fontSize: 20,
marginBottom: 20,
},
input: {
width: "80%",
height: 50,
borderRadius: 10,
borderColor: "gray",
borderWidth: 1,
marginBottom: 20,
padding: 8,
fontSize: 15,
},
button: {
backgroundColor: "#D0291C",
width: "80%",
height: 55,
borderRadius: 20,
marginBottom: 16,
justifyContent: "center",
alignItems: "center",
},
buttonText: {
color: "white",
fontSize: 16,
},
message: {
marginTop: 10,
color: "red",
},
});