diff --git a/src/screens/auth/InputForgotPassword.tsx b/src/screens/auth/InputForgotPassword.tsx index 2776b37f2d10c3b376236bfa01e92c21fa6215b8..53b55b1a88f5cc8fa61e6fb6f05d04ca501b1a42 100644 --- a/src/screens/auth/InputForgotPassword.tsx +++ b/src/screens/auth/InputForgotPassword.tsx @@ -1,7 +1,7 @@ import { useNavigation } from "@react-navigation/core"; import React from "react"; import { useState } from "react"; -import { StyleSheet, View, Text } from "react-native"; +import { StyleSheet, View, Text, Alert } from "react-native"; import Colors from "../../constants/Colors"; import { RootTabScreenProps } from "../../types/navigation"; import PlainForm from "../../components/Forms/PlainForm"; @@ -10,6 +10,7 @@ import { MaterialIcons } from "@expo/vector-icons"; import MainButton from "../../components/button/MainButton"; import firebase from "firebase"; import { validateEmail } from "../../helpers/Validators"; +import { forgotPassword } from "../../service/firebase/auth"; export default function InputForgotPassword({ navigation, @@ -46,10 +47,16 @@ export default function InputForgotPassword({ text={"Reset Password"} colors={"Primary"} onPress={() => { - if (validateEmail(email)) { - firebase.auth().sendPasswordResetEmail(email); - nav.navigate("Auth", { screen: "ForgotPasswordDone" }); - } + forgotPassword(email) + .then(() => + nav.navigate("Auth", { screen: "ForgotPasswordDone" }) + ) + .catch((e) => + Alert.alert( + "Email tidak ditemukan", + "Silahkan masukkan email yang terdaftar" + ) + ); }} /> diff --git a/src/service/firebase/auth.ts b/src/service/firebase/auth.ts index 0dca517124a071ddb5735ba937694bc98f97307b..417b8abdced9a0860444a43c4b22d89e8940cf05 100644 --- a/src/service/firebase/auth.ts +++ b/src/service/firebase/auth.ts @@ -35,3 +35,7 @@ export const changePassword = async (password: string) => { export const signUpAuth = async (email: string, password: string) => { return await firebase.auth().createUserWithEmailAndPassword(email, password); }; + +export const forgotPassword = async (email: string) => { + return await firebase.auth().sendPasswordResetEmail(email); +};