-
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주차 기본/생각 과제 ] 로그인/회원가입 🍁 #7
base: main
Are you sure you want to change the base?
Changes from all commits
0ea956c
40f9a65
3ddce7e
20e1d70
2d234a4
7659d46
d19824b
a3bb3b5
91fb5bc
e78ef23
d5c03bb
1b65037
7ce5043
de02440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.env | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:react/recommended', | ||
'plugin:react/jsx-runtime', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, | ||
settings: { react: { version: '18.2' } }, | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.env | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# React + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="ko"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>week04 과제</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "login-project", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.37", | ||
"@types/react-dom": "^18.2.15", | ||
"@vitejs/plugin-react": "^4.2.0", | ||
"eslint": "^8.53.0", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.4", | ||
"vite": "^5.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import GlobalStyle from "./styles/GlobalStyle"; | ||
import Router from "./components/Router"; | ||
import { ThemeProvider } from "styled-components"; | ||
import theme from "./styles/theme"; | ||
|
||
function App() { | ||
return ( | ||
<> | ||
<ThemeProvider theme={theme}> | ||
<GlobalStyle /> | ||
<Router /> | ||
</ThemeProvider> | ||
</> | ||
); | ||
} | ||
|
||
export default App; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
import { BrowserRouter, Route, Routes } from "react-router-dom"; | ||
import Login from "../pages/Login"; | ||
import Signup from "../pages/Signup"; | ||
import Mypage from "../pages/Mypage"; | ||
|
||
const Router = () => { | ||
return ( | ||
<BrowserRouter> | ||
<Routes> | ||
<Route path="/login" element={<Login />} /> | ||
<Route path="/signup" element={<Signup />} /> | ||
<Route path="/mypage/:userId" element={<Mypage />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
); | ||
}; | ||
|
||
export default Router; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import App from "./App"; | ||
|
||
ReactDOM.createRoot(document.getElementById("root")).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import axios from "axios"; | ||
import React, { useState } from "react"; | ||
import { Link, useNavigate } from "react-router-dom"; | ||
import { St } from "../styles/Design"; | ||
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. 혹시 스타일 파일을 따로 만든 이유가 이쓸까요 ?! 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. 저는, , ,, 여러파일에서 동일한 styled component가 반복해서 쓰이면 그걸 매 파일마다 작성하기 귀찮아증후군이 있기 때문에 ,, 분리해서 import해서 사용하곤합니당 ,, |
||
|
||
const Login = () => { | ||
const navigate = useNavigate(); | ||
const [id, setId] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const onIdChange = (e) => { | ||
setId(e.target.value.toString()); | ||
}; | ||
const onPasswordChange = (e) => { | ||
setPassword(e.target.value.toString()); | ||
}; | ||
const onRegisterBtnClick = () => { | ||
navigate("/signup"); | ||
}; | ||
const onLoginBtnClick = () => { | ||
try { | ||
axios | ||
.post(`${import.meta.env.VITE_BASE_URL}/api/v1/members/sign-in`, { | ||
username: id, | ||
password: password, | ||
}) | ||
.then((res) => { | ||
navigate(`/mypage/${res.data.id}`); | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
return ( | ||
<St.ModalContainer> | ||
<St.ModalBox> | ||
<St.ModalTitle>Login</St.ModalTitle> | ||
<St.InputContainer> | ||
<St.InputCategory>ID</St.InputCategory> | ||
<St.InputBox | ||
required | ||
placeholder="아이디를 입력해주세요" | ||
onChange={onIdChange} | ||
></St.InputBox> | ||
</St.InputContainer> | ||
<St.InputContainer> | ||
<St.InputCategory>PASSWORD</St.InputCategory> | ||
<St.InputBox | ||
placeholder="비밀번호를 입력해주세요" | ||
required | ||
onChange={onPasswordChange} | ||
></St.InputBox> | ||
</St.InputContainer> | ||
<St.ButtonContainer> | ||
<St.SubmitButton type="button" onClick={onLoginBtnClick}> | ||
로그인 | ||
</St.SubmitButton> | ||
<Link to={"/signup"}> | ||
<St.RegisterButton type="button">회원가입</St.RegisterButton> | ||
</Link> | ||
Comment on lines
+57
to
+59
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. Link 자체를 스타일링 하는 방법두 있어용! 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. 헐랭! 합세때 바로 써먹어봐야징 ,, |
||
{/* <St.RegisterButton onClick={onRegisterBtnClick}> | ||
회원가입 | ||
</St.RegisterButton> */} | ||
Comment on lines
+60
to
+62
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. 주석 지우기 얍! |
||
</St.ButtonContainer> | ||
</St.ModalBox> | ||
</St.ModalContainer> | ||
); | ||
}; | ||
|
||
export default Login; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import axios from "axios"; | ||
import React, { useEffect, useState } from "react"; | ||
import { Link, useNavigate, useParams } from "react-router-dom"; | ||
import { St } from "../styles/Design"; | ||
import img from "../assets/5.jpg"; | ||
const Mypage = () => { | ||
const { userId } = useParams(); | ||
const navigate = useNavigate(); | ||
const [username, setUserName] = useState(""); | ||
const [nickname, setNickName] = useState(""); | ||
useEffect(() => { | ||
userId !== "" && getUserInfo(); | ||
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. 이 코드는 결고ㅏ가 어떻게 나오는건가요??!!,,, |
||
}, [userId]); | ||
const getUserInfo = () => { | ||
try { | ||
axios | ||
.get(`${import.meta.env.VITE_BASE_URL}/api/v1/members/${userId}`) | ||
.then((response) => { | ||
setUserName(response.data.username); | ||
setNickName(response.data.nickname); | ||
Comment on lines
+19
to
+20
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.
|
||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
const onLogoutBtnClick = () => { | ||
navigate("/login"); | ||
}; | ||
return ( | ||
<St.ModalContainer> | ||
<St.ModalBox> | ||
<St.ModalTitle>MY PAGE</St.ModalTitle> | ||
<St.UserInfoContainer> | ||
<St.UserProfile src={img} alt="profile" /> | ||
<St.UserInfoBox> | ||
<St.UserInfo>ID : {username}</St.UserInfo> | ||
<St.UserInfo>닉네임 : {nickname}</St.UserInfo> | ||
</St.UserInfoBox> | ||
</St.UserInfoContainer> | ||
<St.ButtonContainer> | ||
<St.SubmitButton type="button" onClick={onLogoutBtnClick}> | ||
로그아웃 | ||
</St.SubmitButton> | ||
</St.ButtonContainer> | ||
</St.ModalBox> | ||
</St.ModalContainer> | ||
); | ||
}; | ||
|
||
export default Mypage; |
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.
오잉 axios가 설치가 안되어 있나용 ?! 확인 해보면 좋을것 같습니댜