import React, { useState } from "react"; import { Button, Text, View } from "react-native"; import ELogo from "@components/ELogo"; import ETextInput from "@components/ETextInput"; import EFullButton, { EIconButton } from "@components/EButton"; import { ColorScheme } from "@components/Design"; import { AppleIcon, GoogleIcon } from "@components/EIcons"; import { ECaptionText, ELabelText } from "@components/EText"; import auth from "@react-native-firebase/auth"; import { useRouter } from "expo-router"; import { GoogleSignin } from "@react-native-google-signin/google-signin"; import { useAuthState } from "@components/AuthProvider"; GoogleSignin.configure({ webClientId: "406674810515-l8a40f83kl5hnvflvcjrabmjmbvda7am.apps.googleusercontent.com", }); export default function LoginScreen(props: any) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(false); const router = useRouter(); const [loginAttempting, setLoginAttempting] = useState(false); const signInWithEmail = async () => { setLoginAttempting(true); try { await auth().signInWithEmailAndPassword(email, password); router.replace("/"); } catch (e) { setError(true); } setLoginAttempting(false); }; const signInWithGoogle = async () => { setLoginAttempting(true); await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true }); const { idToken } = await GoogleSignin.signIn(); const googleCredential = auth.GoogleAuthProvider.credential(idToken); return auth().signInWithCredential(googleCredential); }; const [user, loginstate, setLoginState] = useAuthState(); return ( <> setError(false)} /> setError(false)} /> {error && ( 이메일 혹은 비밀번호가 일치하지 않습니다 )} signInWithEmail()} /> { setLoginState && setLoginState({ ...loginstate, passwordReset: true }); router.push("auth/passwordresetemail"); }} active={true} text={"비밀번호를 모르겠어요"} /> { signInWithGoogle() .then((d) => { console.log("worked!"); setLoginAttempting(false); router.replace(""); }) .catch((e) => { console.error(e); setLoginAttempting(false); }); }} > 아직 회원이 아니신가요? { setLoginState && setLoginState({ ...loginstate, passwordReset: false }); router.push("auth/registeremail"); }} style={{ backgroundColor: ColorScheme.frostedfill.white[10] }} active={true} text={"회원가입"} /> ); }