-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from TaePoong719/feature/#5
Feature/#5
- Loading branch information
Showing
12 changed files
with
1,023 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from "react"; | ||
import { User } from "@firebase/auth"; | ||
|
||
export const AuthContext = React.createContext<User | null>(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { User } from "@firebase/auth"; | ||
import { useEffect, useState } from "react"; | ||
import { AuthContext } from "./authContext"; | ||
import { auth } from "../firebase"; | ||
|
||
interface IChildren { | ||
children : React.JSX.Element | ||
} | ||
|
||
const AuthProvider = ({ children }: IChildren) => { | ||
const [user, setUser] = useState<User | null>(null); | ||
|
||
useEffect(() => { | ||
const subscribe = auth.onAuthStateChanged(fbUser => { | ||
console.log(`현재 유저 정보`, fbUser); | ||
setUser(fbUser); | ||
}); | ||
return subscribe; | ||
}, []); | ||
|
||
return <AuthContext.Provider value={user}>{children}</AuthContext.Provider>; | ||
}; | ||
|
||
export default AuthProvider; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Import the functions you need from the SDKs you need | ||
import { initializeApp } from "firebase/app"; | ||
import { getAuth } from 'firebase/auth' | ||
// TODO: Add SDKs for Firebase products that you want to use | ||
// https://firebase.google.com/docs/web/setup#available-libraries | ||
|
||
// Your web app's Firebase configuration | ||
const firebaseConfig = { | ||
apiKey: "AIzaSyBjMrRAvL85KYQ6okbz7FPTy_iJ6EnSPn0", | ||
authDomain: "fastcampus-wiki.firebaseapp.com", | ||
projectId: "fastcampus-wiki", | ||
storageBucket: "fastcampus-wiki.appspot.com", | ||
messagingSenderId: "38983729603", | ||
appId: "1:38983729603:web:395c72acc46e26b15f3d76" | ||
}; | ||
|
||
// Initialize Firebase | ||
export const app = initializeApp(firebaseConfig); | ||
export const auth = getAuth(app); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.authentication__form{ | ||
display: flex; | ||
flex-flow: column; | ||
gap: 30px; | ||
margin-bottom: 40px; | ||
width: 300px; | ||
} | ||
|
||
.authentication__form-el{ | ||
display: flex; | ||
} | ||
|
||
.authentication__form-el label{ | ||
flex: 0 0 80px; | ||
height: 30px; | ||
} | ||
|
||
.authentication__form-el input{ | ||
flex: 0 0 200px; | ||
} | ||
|
||
.authentication__form .btn{ | ||
width: 175px; | ||
height: 48px; | ||
margin: 20px auto; | ||
background-color: var(--main-color); | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
box-sizing: border-box; | ||
cursor: pointer; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useState } from 'react' | ||
import styled from 'styled-components' | ||
import { auth } from '../firebase' | ||
import { Link } from 'react-router-dom'; | ||
import { signInWithEmailAndPassword } from 'firebase/auth'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import './Authentication.css' | ||
|
||
const Login = () => { | ||
const [email, setEmail] = useState(""); | ||
const [pwd, setPwd] = useState(""); | ||
const navigate = useNavigate() | ||
|
||
const handleEmail = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
e.preventDefault(); | ||
setEmail(e.target.value); | ||
}; | ||
|
||
const handlePwd = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
e.preventDefault(); | ||
setPwd(e.target.value); | ||
}; | ||
|
||
const handleSubmit = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
|
||
signInWithEmailAndPassword(auth, email, pwd) | ||
.then(() => { | ||
alert("로그인 성공"); | ||
navigate("/") | ||
}) | ||
.catch(e => { | ||
alert(e); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<h1> 로그인</h1> | ||
<form className="authentication__form" onSubmit={handleSubmit}> | ||
<div className="authentication__form-el"><label htmlFor="id"> 이메일 </label> <input type="email" id="email" onChange={handleEmail} value={email} /></div> | ||
<div className="authentication__form-el"><label htmlFor="pwd"> 비밀번호 </label> <input type="password" id="pwd" onChange={handlePwd} value={pwd} /></div> | ||
<button className="btn" type="submit"> 로그인 </button> | ||
</form> | ||
<Link to={`/signup`}> <b>회원가입</b> </Link> | ||
</Container> | ||
) | ||
} | ||
|
||
const Container = styled.main` | ||
margin: 0 auto; | ||
margin-top: 60px; | ||
width: 90%; | ||
max-width: 800px; | ||
height: 500px; | ||
border: 1.5px solid var(--main-color); | ||
border-radius: 0.8rem; | ||
padding : 20px 5px; | ||
box-sizing: border-box; | ||
display: flex; | ||
flex-flow: column; | ||
align-items: center; | ||
h1{ | ||
margin-bottom:5rem; | ||
} | ||
b{ | ||
text-decoration: underline solid black 1.5px ; | ||
} | ||
` | ||
|
||
export default Login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { auth } from '../firebase'; | ||
import { createUserWithEmailAndPassword, signOut, updateProfile } from 'firebase/auth'; | ||
import React, { useState } from 'react' | ||
import styled from 'styled-components' | ||
import { useNavigate } from 'react-router-dom'; | ||
import './Authentication.css' | ||
|
||
const SignUp = () => { | ||
const [email, setEmail] = useState(""); | ||
const [pwd, setPwd] = useState(""); | ||
const [nickname, setNickname] = useState(""); | ||
const navigate = useNavigate() | ||
|
||
const handleEmail = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
e.preventDefault() | ||
setEmail(e.target.value) | ||
} | ||
|
||
const handlePwd = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
e.preventDefault() | ||
setPwd(e.target.value) | ||
} | ||
|
||
const handleNickname = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
e.preventDefault() | ||
setNickname(e.target.value) | ||
} | ||
|
||
const handleClickCreate = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
try{ | ||
const userCredential = await createUserWithEmailAndPassword(auth, email, pwd) | ||
if(userCredential){ | ||
await updateProfile(userCredential.user, { | ||
displayName: nickname | ||
}) | ||
} | ||
signOut(auth) | ||
alert('회원가입이 완료됐습니다.') | ||
navigate("/login") | ||
}catch(e){ | ||
alert(e) | ||
} | ||
} | ||
|
||
return ( | ||
<Container> | ||
<h1> 회원 가입</h1> | ||
<form className="authentication__form" onSubmit={handleClickCreate}> | ||
<div className="authentication__form-el"><label htmlFor="id"> 이메일 </label> <input type="email" id="email" onChange={handleEmail} value={email} /></div> | ||
<div className="authentication__form-el"><label htmlFor="pwd"> 비밀번호 </label> <input type="password" id="pwd" onChange={handlePwd} value={pwd} /></div> | ||
<div className="authentication__form-el"><label htmlFor="nickname"> 닉네임 </label> <input type="text" id="nickname" onChange={handleNickname} value={nickname} /></div> | ||
<button className="btn" type="submit"> 회원 가입 </button> | ||
</form> | ||
</Container> | ||
) | ||
} | ||
const Container = styled.main` | ||
margin: 0 auto; | ||
margin-top: 60px; | ||
width: 90%; | ||
max-width: 800px; | ||
height: 500px; | ||
border: 1.5px solid var(--main-color); | ||
border-radius: 0.8rem; | ||
padding : 20px 5px; | ||
box-sizing: border-box; | ||
display: flex; | ||
flex-flow: column; | ||
align-items: center; | ||
h1{ | ||
margin-bottom:5rem; | ||
} | ||
` | ||
export default SignUp |