-
Notifications
You must be signed in to change notification settings - Fork 79
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
[김혜선] sprint11 #684
Merged
ding-co
merged 10 commits into
codeit-bootcamp-frontend:Next.js-김혜선
from
kim-hye-sun:Next.js-김혜선
Jun 18, 2024
The head ref may contain hidden characters: "Next.js-\uAE40\uD61C\uC120"
Merged
[김혜선] sprint11 #684
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
807616f
✨ feat: 자유게시판 목록 pageSize:10000 -> 무한스크롤 작업
kim-hye-sun 34f1037
✨ feat: metadata 설정
kim-hye-sun 4d5982f
♻️ refactor: 사용하지 않는 document 코드 정리
kim-hye-sun e5b5b78
♻️ refactor: comment API 기존 board.ts에서 분리
kim-hye-sun 8552110
✨ feat: 자유게시판 상세페이지 좋아요 추가, 해제 기능 작업
kim-hye-sun 8e34718
✨ feat: 상세페이지 더보기 게시글 수정, 삭제 작업
kim-hye-sun 1f0c7c2
✨ feat: 회원가입 기능 구현
kim-hye-sun ff45de3
✨ feat: 회원가입 폼 하단 sns view 작업
kim-hye-sun 4ffed1d
✨ feat: 헤더 작업 (nav 활성화를 위한 폴더 구조 변경 및 getAccessToken -> signIn 메소드명 변경)
kim-hye-sun f291ec0
🐛 fix: 회원가입, 로그인 버튼 활성화, 비활성화 동작 오류
kim-hye-sun 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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { ISignUpUser, IUser } from "@/@types"; | ||
import { ISignInUser, ISignUpUser, IUser } from "@/@types"; | ||
import { API_URL } from "@/app/containts"; | ||
import { saveTokens } from "./authTokens"; | ||
|
||
interface SignUpResponse { | ||
success: boolean; | ||
user: IUser; | ||
message: string; | ||
} | ||
|
||
|
@@ -18,24 +18,53 @@ export async function signUp(data: ISignUpUser): Promise<SignUpResponse> { | |
body: JSON.stringify(data), | ||
}); | ||
const json = await res.json(); | ||
//동일한 이메일, 닉네임이 있을 경우 | ||
if (res.status === 400) { | ||
return { | ||
success: true, | ||
user: {} as IUser, | ||
message: json.message, | ||
}; | ||
} else { | ||
return { | ||
success: true, | ||
user: json, | ||
message: "회원 가입이 성공적으로 완료되었습니다.", | ||
}; | ||
} | ||
} catch (e) { | ||
return { | ||
success: false, | ||
user: {} as IUser, | ||
message: "회원 가입 중 오류가 발생했습니다. 다시 시도해주세요.", | ||
}; | ||
} | ||
} | ||
|
||
//토큰 가져오기 -> 로그인 임 | ||
export async function signIn(userData: ISignInUser): Promise<SignUpResponse> { | ||
const res = await fetch(`${API_URL}/auth/signIn`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(userData), | ||
}); | ||
const json = await res.json(); | ||
|
||
// 토큰 저장 | ||
const accessToken = json.accessToken; | ||
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. destructuring 하면 좋을 것 같아요. |
||
const refreshToken = json.refreshToken; | ||
const userId = json.user.id; | ||
|
||
saveTokens(accessToken, userId, refreshToken); | ||
|
||
try { | ||
return { | ||
success: true, | ||
message: "로그인이 성공적으로 완료되었습니다.", | ||
}; | ||
} catch (e) { | ||
return { | ||
success: false, | ||
message: "로그인 중 오류가 발생했습니다. 다시 시도해주세요.", | ||
}; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,16 +3,17 @@ import { API_URL } from "../containts"; | |
// 토큰 저장 함수 | ||
export function saveTokens( | ||
accessToken: string, | ||
userid: string, | ||
userid?: string, | ||
refreshToken?: string | ||
) { | ||
localStorage.setItem("accessToken", accessToken); | ||
if (refreshToken) { | ||
localStorage.setItem("refreshToken", refreshToken); | ||
} | ||
|
||
//임시 유저 정보 저장 | ||
localStorage.setItem("userid", userid); | ||
if (userid) { | ||
//임시 유저 정보 저장 | ||
localStorage.setItem("userid", userid); | ||
} | ||
} | ||
|
||
// 토큰 가져오기 함수 | ||
|
@@ -33,8 +34,7 @@ export async function refreshAccessToken(refreshToken: string) { | |
}); | ||
const data = await res.json(); | ||
const { accessToken } = data; | ||
const { id } = data.user.id; | ||
saveTokens(accessToken, id); | ||
saveTokens(accessToken); | ||
return accessToken; | ||
} | ||
|
||
|
@@ -44,29 +44,10 @@ export async function validateAndRefreshTokens() { | |
if (!accessToken || !refreshToken) { | ||
throw new Error("No tokens found"); | ||
} | ||
|
||
const isTokenExpired = false; | ||
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. false로 값을 고정시킨 이유가 있을까요. |
||
if (isTokenExpired) { | ||
return await refreshAccessToken(refreshToken); | ||
} | ||
|
||
return accessToken; | ||
} | ||
|
||
//토큰 가져오기 | ||
export async function getAccessToken() { | ||
const res = await fetch(`${API_URL}/auth/signIn`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ email: "[email protected]", password: "z100004z" }), | ||
}); | ||
const data = await res.json(); | ||
const accessToken = data.accessToken; | ||
const refreshToken = data.refreshToken; | ||
const userId = data.user.id; | ||
|
||
// 토큰 저장 | ||
saveTokens(accessToken, userId, refreshToken); | ||
} |
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
File renamed without changes.
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
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 |
---|---|---|
@@ -1,22 +1,3 @@ | ||
"use client"; | ||
import Image from "next/image"; | ||
import styles from "./page.module.css"; | ||
import { getAccessToken } from "./api/authTokens"; | ||
import { useEffect } from "react"; | ||
|
||
export default function Home() { | ||
//처음 메인 페이지 들어오면 토큰 발급 | ||
useEffect(() => { | ||
const fetchAccessToken = async () => { | ||
try { | ||
const accessToken = await getAccessToken(); | ||
} catch (error) { | ||
console.error("Error fetching access token:", error); | ||
} | ||
}; | ||
|
||
fetchAccessToken(); | ||
}, []); // 빈 배열은 컴포넌트가 처음 렌더링될 때 한 번만 실행 | ||
|
||
return <div>main</div>; | ||
} |
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,7 @@ | ||
export default function Product() { | ||
return ( | ||
<div> | ||
<h1>product 페이지입니다.</h1> | ||
</div> | ||
); | ||
} |
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.
import type으로 작성하실 수 있을 것 같아요.