-
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 #33 from KGU-C-Lab/feat/auth
- Loading branch information
Showing
60 changed files
with
877 additions
and
274 deletions.
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
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 @@ | ||
export interface ServerResponse<T = unknown> { | ||
success: boolean; | ||
data: T; | ||
} |
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,4 +1,8 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
const nextConfig = { | ||
experimental: { | ||
missingSuspenseWithCSRBailout: false, | ||
}, | ||
}; | ||
|
||
export default nextConfig; |
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,2 @@ | ||
VITE_MODE=환경모드 | ||
VITE_API_BASE_URL=API주소 |
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
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,14 @@ | ||
import { PaginationType } from '@type/api'; | ||
import { server } from './server'; | ||
import { END_POINT } from '@constants/api'; | ||
import type { BoardItem } from '@type/board'; | ||
import { createPagination } from '@utils/api'; | ||
|
||
// 내가 작성한 커뮤니티 게시글 조회 | ||
export const getMyBoards = async (page: number, size: number) => { | ||
const { data } = await server.get<PaginationType<BoardItem>>({ | ||
url: createPagination(END_POINT.MY_BOARDS, page, size), | ||
}); | ||
|
||
return data; | ||
}; |
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,16 @@ | ||
import { PaginationType } from '@type/api'; | ||
import { server } from './server'; | ||
import { createPagination } from '@utils/api'; | ||
import { END_POINT } from '@constants/api'; | ||
import { BookItem } from '@type/book'; | ||
|
||
// 나의 대출내역 조회 | ||
export const getMyBooks = async (page: number, size: number, id: number) => { | ||
const { data } = await server.get<PaginationType<BookItem>>({ | ||
url: createPagination(END_POINT.MY_BOOKS, page, size), | ||
}); | ||
const myLoanBooks = data.items.filter( | ||
(book) => book.borrowerId === String(id), | ||
); | ||
return myLoanBooks; | ||
}; |
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,14 @@ | ||
import { PaginationType } from '@type/api'; | ||
import { server } from './server'; | ||
import { createPagination } from '@utils/api'; | ||
import { END_POINT } from '@constants/api'; | ||
import type { CommentItem } from '@type/comment'; | ||
|
||
// 나의 댓글 조회 | ||
export const getMyComments = async (page: number, size: number) => { | ||
const { data } = await server.get<PaginationType<CommentItem>>({ | ||
url: createPagination(END_POINT.MY_COMMENTS, page, size), | ||
}); | ||
|
||
return data; | ||
}; |
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 { server } from './server'; | ||
import { API_BASE_URL, END_POINT } from '@constants/api'; | ||
import type { Interceptor } from '@gwansikk/server-chain'; | ||
import type { BaseResponse, TokenType } from '@type/api'; | ||
import { | ||
authorization, | ||
getAccessToken, | ||
getRefreshToken, | ||
removeTokens, | ||
setTokens, | ||
} from '@utils/api'; | ||
|
||
let reissueLock = false; | ||
|
||
const retryRequest = async ( | ||
response: Response, | ||
method: string, | ||
delay = 300, | ||
) => { | ||
await new Promise((resolve) => setTimeout(resolve, delay)); // 재요청 딜레이 | ||
|
||
const accessToken = getAccessToken(); | ||
return fetch(response.url, { | ||
method: method, | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}; | ||
|
||
export const tokenHandler: Interceptor<Response> = async (response, method) => { | ||
const { status } = response; | ||
|
||
if (status === 401) { | ||
const preRefreshToken = getRefreshToken(); | ||
if (!preRefreshToken) return response; | ||
|
||
if (reissueLock) { | ||
// 잠금이 걸려있는 경우, 토큰 갱신 될 때까지 재요청 | ||
return retryRequest(response, method); | ||
} else { | ||
// 토큰 갱신 중복 요청 방지 | ||
reissueLock = true; | ||
} | ||
|
||
const tokenResponse = await fetch( | ||
`${API_BASE_URL}${END_POINT.LOGIN_REISSUE}`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${preRefreshToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
|
||
const { success, data } = | ||
(await tokenResponse.json()) as BaseResponse<TokenType>; | ||
|
||
if (success === true) { | ||
const { accessToken, refreshToken } = data; | ||
setTokens(accessToken, refreshToken); | ||
server.setHeaders(authorization(accessToken)); | ||
reissueLock = false; | ||
return retryRequest(response, method, 0); | ||
} else { | ||
// 토큰 갱신에 실패한 경우 로그아웃 처리 | ||
removeTokens(); | ||
window.location.reload(); | ||
} | ||
} | ||
|
||
return response; | ||
}; |
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 { server } from './server'; | ||
import { END_POINT } from '@constants/api'; | ||
import type { BaseResponse } from '@type/api'; | ||
import type { MemberType } from '@type/member'; | ||
|
||
interface PatchUserInfoArgs { | ||
id: string; | ||
body: MemberType; | ||
} | ||
|
||
// 내 정보 수정 | ||
export const patchUserInfo = async ({ id, body }: PatchUserInfoArgs) => { | ||
const { data } = await server.patch<MemberType, BaseResponse<MemberType>>({ | ||
url: END_POINT.MY_INFO_EDIT(id), | ||
body: body, | ||
}); | ||
|
||
return data; | ||
}; |
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,14 @@ | ||
import { PaginationType } from '@type/api'; | ||
import { server } from './server'; | ||
import type { NotificationItem } from '@type/notification'; | ||
import { createPagination } from '@utils/api'; | ||
import { END_POINT } from '@constants/api'; | ||
|
||
// 나의 알림 조회 | ||
export const getMyNotifications = async (page: number, size: number) => { | ||
const { data } = await server.get<PaginationType<NotificationItem>>({ | ||
url: createPagination(END_POINT.MY_NOTIFICATION, page, size), | ||
}); | ||
|
||
return data; | ||
}; |
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,14 @@ | ||
import ServerChain from '@gwansikk/server-chain'; | ||
import { tokenHandler } from './interceptors'; | ||
import { API_BASE_URL } from '@constants/api'; | ||
|
||
export const server = ServerChain({ | ||
key: 'server', | ||
baseURL: API_BASE_URL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
interceptors: { | ||
error: tokenHandler, | ||
}, | ||
}); |
21 changes: 21 additions & 0 deletions
21
apps/member/src/components/common/LoginButton/LoginButton.tsx
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,21 @@ | ||
import Image from '../Image/Image'; | ||
|
||
const LoginButton = () => { | ||
const handleClick = () => { | ||
window.location.href = 'https://auth.clab.page/?code=dev'; | ||
}; | ||
|
||
return ( | ||
<button | ||
onClick={handleClick} | ||
className="max-w-xs flex items-center border border-black py-2 px-4 bg-[#292d32] gap-4 rounded-md w-full" | ||
> | ||
<Image src="/logo.webp" alt="C-Lab" width="w-8" height="h-8" /> | ||
<span className="text-white font-semibold text-center grow"> | ||
C-Lab Auth로 로그인 | ||
</span> | ||
</button> | ||
); | ||
}; | ||
|
||
export default LoginButton; |
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
Oops, something went wrong.