From e10bc04df420fdff587906b1ba69890135b0bce6 Mon Sep 17 00:00:00 2001 From: SugarSyrup Date: Sun, 11 Feb 2024 22:51:28 +0900 Subject: [PATCH] =?UTF-8?q?feat(#4):=20isLoginTemplate=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/CollectPersonalData.jsx | 48 +++++++++++++++---------------- src/pages/IsLoginTemplate.jsx | 21 ++++++++------ src/service/auth.js | 26 ++++++++--------- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/pages/CollectPersonalData.jsx b/src/pages/CollectPersonalData.jsx index eeec1dc..fc16a9f 100644 --- a/src/pages/CollectPersonalData.jsx +++ b/src/pages/CollectPersonalData.jsx @@ -1,7 +1,7 @@ import HeaderBox from "../components/common/header/HeaderBox"; import Button from "../components/common/Button"; import Terms from "../components/common/Terms"; -import TermsBox from "../components/collectPersonalData/TermsBox"; +import TermsBox from "../components/CollectPersonalData/TermsBox"; import styled from "styled-components"; import { Context } from "../components/context/context"; import { useContext } from "react"; @@ -9,30 +9,30 @@ import SignUpProvider from "../components/provider/SignUpPovider"; import BackHeader from "../components/common/header/BackHeader"; export default function CollectPersonalData() { - return ( - <> - - -
- - 서비스 이용을 위해 - {"약관 동의를 해주세요 :)"} - -
-
- - ); + return ( + <> + + +
+ + 서비스 이용을 위해 + {"약관 동의를 해주세요 :)"} + +
+
+ + ); } const Section = styled.section` - width: 360px; - height: 500px; - display: flex; - flex-direction: column; - align-items: center; - justify-content: space-between; - /* background-color: aqua; */ + width: 360px; + height: 500px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + /* background-color: aqua; */ `; diff --git a/src/pages/IsLoginTemplate.jsx b/src/pages/IsLoginTemplate.jsx index eba0b97..1ce1607 100644 --- a/src/pages/IsLoginTemplate.jsx +++ b/src/pages/IsLoginTemplate.jsx @@ -1,17 +1,22 @@ import { useNavigate } from "react-router-dom"; import { useEffect } from "react"; -import { firebaseAuth } from "../service/firebaseConfig"; +import { onAuthStateChanged } from "firebase/auth"; +import { auth } from "../service/auth"; function IsLoginTemplate(props) { - const navigate = useNavigate(); + const navigate = useNavigate(); - useEffect(() => { - if (firebaseAuth.currentUser) { - navigate("/Home"); - } - }, []); + useEffect(() => { + onAuthStateChanged(auth, (user) => { + if (user) { + navigate("/Home"); + } else { + navigate("/Login"); + } + }); + }, [auth]); - return <>{props.children}; + return <>{props.children}; } export default IsLoginTemplate; diff --git a/src/service/auth.js b/src/service/auth.js index 1613b36..e035d5a 100644 --- a/src/service/auth.js +++ b/src/service/auth.js @@ -3,19 +3,19 @@ import { firebaseAuth } from "./firebaseConfig"; const provider = new GoogleAuthProvider(); -const auth = firebaseAuth; +export const auth = firebaseAuth; export const signInWithGoogle = () => { - signInWithPopup(auth, provider) - .then((result) => { - const credential = GoogleAuthProvider.credentialFromResult(result); - const token = credential.accessToken; - const user = result.user; - }) - .catch((err) => { - const errorCode = err.code; - const errorMessage = err.message; - const email = err.customData.email; - const credential = GoogleAuthProvider.credentialFromError(err); - }); + signInWithPopup(auth, provider) + .then((result) => { + const credential = GoogleAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + const user = result.user; + }) + .catch((err) => { + const errorCode = err.code; + const errorMessage = err.message; + const email = err.customData.email; + const credential = GoogleAuthProvider.credentialFromError(err); + }); };