-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4주차 기본/심화/생각 과제] 🍁 로그인/회원가입 #4
Open
namdaeun
wants to merge
23
commits into
main
Choose a base branch
from
week4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
37d9593
Feat: inital setting
namdaeun 85aa43f
Docs: add MyPage
namdaeun 99fe6b4
Feat: add Router.jsx
namdaeun bd50156
Feat: 회원가입 API 연결 + 스타일 파일 생성
namdaeun 866615a
Feat: 비밀번호 확인 & 회원가입 버튼 활성화하는 함수 생성
namdaeun b3cd281
Feat: 아이디 중복 확인
namdaeun cc2d4f3
Feat: useEffect 조건 수정
namdaeun e8b5a50
Feat: 회원가입 버튼 누르면 로그인 페이지로 이동
namdaeun b51a3ed
Design: 회원가입 스타일 적용
namdaeun 6955067
Design: 전체 UI 스타일 적용
namdaeun 4d73a2e
Feat: 입력하고 있는 도중에는 중복 확인 버튼 검정색
namdaeun 8244f43
Feat: 회원가입 버튼 누르면 Signup으로 이동
namdaeun 4fd831a
Feat: 로그인 버튼 누르면 정보 가져오고 mypage로 이동
namdaeun f6aa91b
Feat: 로그인 버튼 누르면 Login으로 이동
namdaeun e5f379f
Feat: 로그인 데이터 가져와서 화면에 띄우기
namdaeun 0274977
Feat: 생각과제
namdaeun 4c5e50a
Remove: Header 파일 제거
namdaeun d48d0a3
Feat: toast
namdaeun c7cae17
Feat: Toast 재구현
namdaeun b5c07f8
Docs: 빈 칸 제거
namdaeun f653d21
Feat: toast 아이디 위치에 토스트 문구 띄우도록 html 코드 추가
namdaeun 2b0b510
Docs: Router만 불러오기
namdaeun a7a690a
Feat: 프로필 사진 띄우기
namdaeun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,13 @@ | ||
<!doctype html> | ||
<html lang="ko"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>로그인 & 회원가입</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<div id="toast"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
Empty file.
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,15 @@ | ||
import Router from './components/Router'; | ||
import './App.css' | ||
import { GlobalStyle } from './style/GlobalStyle'; | ||
|
||
function App() { | ||
|
||
return ( | ||
<> | ||
<GlobalStyle /> | ||
<Router /> | ||
</> | ||
) | ||
} | ||
|
||
export default App |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,18 @@ | ||
import { BrowserRouter, Routes, Route } from 'react-router-dom'; | ||
import SignUp from '../pages/SignUp/SignUp'; | ||
import Login from '../pages/Login/Login'; | ||
import MyPage from '../pages/MyPage/MyPage'; | ||
|
||
const Router = () => { | ||
return ( | ||
<BrowserRouter> | ||
<Routes> | ||
<Route path='/signup' element={<SignUp />} /> | ||
<Route path='/login' element={<Login />} /> | ||
<Route path='/mypage/:userId' element={<MyPage />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
); | ||
}; | ||
|
||
export default Router; |
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,32 @@ | ||
import { useEffect } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
import styled from 'styled-components'; | ||
|
||
const Toast = ({ error, setError, errMessage }) => { | ||
useEffect(() => { | ||
setTimeout(() => { | ||
setError(false); | ||
}, 2000); | ||
}, [error]); | ||
|
||
return createPortal( | ||
<ToastWrapper> | ||
<ToastMessage>{errMessage}</ToastMessage> | ||
</ToastWrapper>, document.getElementById("toast") | ||
); | ||
}; | ||
|
||
export default Toast; | ||
|
||
const ToastWrapper = styled.div` | ||
background-color: var(--color-bg); | ||
position: fixed; | ||
bottom: 11rem; | ||
right: 25rem; | ||
padding: 0.6rem; | ||
border-radius: 1rem; | ||
`; | ||
|
||
const ToastMessage = styled.div` | ||
color: black; | ||
`; |
Empty file.
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,10 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.jsx' | ||
import './index.css' | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
) |
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,78 @@ | ||
import { useState } from 'react'; | ||
import * as S from './style'; | ||
import axios from "axios"; | ||
import Toast from '../../components/Toast'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const Login = () => { | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [error, setError] = useState(false); | ||
const [errMessage, setErrMessage] = useState(""); | ||
const navigate = useNavigate(); | ||
const saveUsername = (event) => { | ||
setUsername(event.target.value); | ||
}; | ||
|
||
const savePassword = (event) => { | ||
setPassword(event.target.value); | ||
}; | ||
|
||
const moveSignupPage = () => { | ||
navigate(`/signup`); | ||
}; | ||
|
||
const getData = async () => { | ||
try { | ||
const res = await axios.post(`${import.meta.env.VITE_BASE_URL}/api/v1/members/sign-in`, { | ||
username: username, | ||
password: password, | ||
}) | ||
console.log("✨성공🤩✨"); | ||
console.log(`아이디 : ${res.data.username}`); | ||
console.log(`비번 : ${res.data.password}`); | ||
navigate(`/mypage/${res.data.id}`); | ||
} catch (err) { | ||
setError(true); | ||
setErrMessage(err.response.data.message); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<S.Container> | ||
<S.InputContainer> | ||
<S.PageTitle>Login</S.PageTitle> | ||
<S.Field className='id-field'>ID</S.Field> | ||
<input | ||
type="text" | ||
size="25" | ||
placeholder="아이디를 입력해주세요" | ||
value={username} | ||
onChange={saveUsername} /> | ||
<S.Field className='pw-field'>PASSWORD</S.Field> | ||
<input | ||
type="text" | ||
size="25" | ||
placeholder="비밀번호를 입력해주세요" | ||
value={password} | ||
onChange={savePassword} /> | ||
</S.InputContainer> | ||
<S.ButtonContainer> | ||
<S.Button type="button" onClick={getData}>로그인</S.Button> | ||
<S.SignUpBtn type="button" onClick={moveSignupPage}>회원가입</S.SignUpBtn> | ||
</S.ButtonContainer> | ||
</S.Container> | ||
{error ? | ||
<Toast | ||
error={error} | ||
setError={setError} | ||
errMessage={errMessage} | ||
></Toast> | ||
: null | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
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,77 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
width: 23rem; | ||
height: 25rem; | ||
background-color: var(--color-bg); | ||
border-radius: 1rem; | ||
display: inline-block; | ||
flex-direction: column; | ||
box-shadow: 12px 15px 63px -1px rgba(0,0,0,0.81); | ||
-webkit-box-shadow: 12px 15px 63px -1px rgba(0,0,0,0.81); | ||
-moz-box-shadow: 12px 15px 63px -1px rgba(0,0,0,0.81); | ||
`; | ||
|
||
export const PageTitle = styled.h3` | ||
text-align: center; | ||
font-size: 1.5rem; | ||
font-weight: bold; | ||
padding: 2rem; | ||
margin-bottom: 1rem; | ||
color: var(--color-accent); | ||
`; | ||
|
||
export const InputContainer = styled.div` | ||
line-height: 40px; | ||
`; | ||
|
||
export const ButtonContainer = styled.div` | ||
display: block; | ||
margin-left: 4rem; | ||
margin-top: 3rem; | ||
`; | ||
|
||
export const Field = styled.div` | ||
display: inline; | ||
margin-right: 1.5rem; | ||
margin-left: 2rem; | ||
&.id-field { | ||
margin-right: 6rem; | ||
} | ||
&.pwd-field { | ||
margin-right: 3.5rem; | ||
} | ||
`; | ||
|
||
export const Button = styled.button` | ||
display: block; | ||
width: 70%; | ||
margin: 1rem; | ||
padding: 0.4rem; | ||
border-radius: 0.5rem; | ||
font-weight: bold; | ||
border: solid; | ||
background-color: var(--color-button-bg); | ||
color: var(--color-accent); | ||
&:hover { | ||
background-color: var(--color-accent); | ||
color: var(--color-button-bg); | ||
font-weight: bold; | ||
} | ||
`; | ||
|
||
export const SignUpBtn = styled.button` | ||
display: block; | ||
width: 70%; | ||
margin: 1rem; | ||
padding: 0.4rem; | ||
border-radius: 0.5rem; | ||
font-weight: bold; | ||
border: solid; | ||
text-align: center; | ||
&:hover { | ||
background-color: #000000; | ||
color: #FF1493; | ||
font-weight: bold; | ||
} | ||
`; |
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,48 @@ | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import axios from "axios"; | ||
import * as S from './style'; | ||
import { useState } from 'react'; | ||
import profileImg from "../../assets/profile/profile.png"; | ||
|
||
const MyPage = () => { | ||
const { userId } = useParams(); | ||
const navigate = useNavigate(); | ||
const [username, setUsername] = useState(""); | ||
const [nickname, setNickname] = useState(""); | ||
|
||
const moveLoginPage = () => { | ||
navigate(`/login`); | ||
}; | ||
|
||
const getLoginData = async () => { | ||
try { | ||
axios.get(`${import.meta.env.VITE_BASE_URL}/api/v1/members/${userId}`, { | ||
userId: userId, | ||
}).then((response) => { | ||
setUsername(response.data.username); | ||
setNickname(response.data.nickname); | ||
console.log("✨🔥성공🔥✨"); | ||
|
||
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p4) then을 사용한 이유가 궁금해! try 에서는 성공하면 바로 변수에 담아서 set함수 사용가능하지 않나?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get이 성공한 경우에만 set하도록 저렇게 적었어요!..흠 then을 사용하지 않으면 get에 성공한 값을 어떻게 불러올 수 있나요,,?? |
||
}) | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
getLoginData(); | ||
|
||
return ( | ||
<S.Container> | ||
<S.PageTitle>MY PAGE</S.PageTitle> | ||
<S.Profile src={profileImg} /> | ||
<S.TextArea> | ||
ID : {username} | ||
</S.TextArea> | ||
<S.TextArea> | ||
닉네임 : {nickname} | ||
</S.TextArea> | ||
<S.Button type="button" onClick={moveLoginPage}>로그아웃</S.Button> | ||
</S.Container> | ||
); | ||
}; | ||
|
||
export default MyPage; |
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,50 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
width: 23rem; | ||
height: 20rem; | ||
line-height: 40px; | ||
background-color: var(--color-bg); | ||
border-radius: 1rem; | ||
display: inline-block; | ||
flex-direction: column; | ||
-webkit-box-shadow: 0px 0px 17px 1px rgba(93,93,93,0.72); | ||
box-shadow: 0px 0px 17px 1px rgba(93,93,93,0.72); | ||
`; | ||
|
||
export const PageTitle = styled.h3` | ||
text-align: center; | ||
font-size: 1.5rem; | ||
padding: 2rem; | ||
font-weight: bold; | ||
padding-bottom: 0; | ||
`; | ||
|
||
export const TextArea = styled.div` | ||
text-align: center; | ||
background-color: var(--color-light-pink); | ||
font-size: 1rem; | ||
font-weight: bold; | ||
padding: 0.2rem; | ||
`; | ||
|
||
export const Profile = styled.img` | ||
width: 4rem; | ||
height: auto; | ||
margin-left: 9.5rem; | ||
`; | ||
|
||
export const Button = styled.button` | ||
display: block; | ||
width: 70%; | ||
margin-left: 3.5rem; | ||
margin-top: 1.5rem; | ||
padding: 0.4rem; | ||
border-radius: 0.5rem; | ||
border: solid; | ||
&:hover { | ||
background-color: var(--color-button-bg); | ||
color: var(--color-light-pink); | ||
font-weight: bold; | ||
} | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p4) shadow까지 넣어주고 세심하게 신경쓴게 보인다!! good~!