Skip to content

Commit b4ef828

Browse files
임시 로그인 추가 (#50)
* fix: 임시 로그인 계정 코드 삽입 * fix: store link * feat: logout용 mock추가 * feat: sidemenu에 signout 버튼 추가 * fix: login fixture 리턴값 수정 --------- Co-authored-by: AyoungWon <wayinwayne@gmail.com>
1 parent 74141c1 commit b4ef828

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

src/common/components/layout/index.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import { Link } from 'react-router-dom';
55
import colors from 'styles/color';
66
import Menus from 'common/components/layout/menus';
77
import { Search, Logo } from 'common/components/icons';
8+
import useAuth from 'common/hooks/useAuth';
89

910
interface Props extends HTMLAttributes<HTMLDivElement> {
1011
children: ReactNode;
1112
}
1213

1314
const Layout = ({ children }: Props) => {
15+
const { logout } = useAuth([]);
1416
return (
1517
<div css={_container}>
1618
<aside css={_sideMenu}>
@@ -22,6 +24,9 @@ const Layout = ({ children }: Props) => {
2224
<nav aria-label="Sidebar navigation" css={_menuContainer}>
2325
<Menus />
2426
</nav>
27+
<button onClick={logout} css={_signout}>
28+
Sign out
29+
</button>
2530
</aside>
2631
<div css={_wrapper}>
2732
<header css={_header}>
@@ -58,6 +63,10 @@ const _sideMenu = css`
5863
width: 345px;
5964
background-color: rgba(255, 255, 255, 1);
6065
filter: drop-shadow(18px 4px 30px #00000002);
66+
height: 100%;
67+
display: flex;
68+
flex-direction: column;
69+
padding-bottom: 24px;
6170
`;
6271

6372
const _wrapper = css`
@@ -145,3 +154,12 @@ const _main = css`
145154
146155
padding: 32px; // 메인 컴포넌트 기본 패딩
147156
`;
157+
158+
const _signout = css`
159+
margin-top: auto;
160+
cursor: pointer;
161+
transition: opacity 0.7s;
162+
:hover {
163+
opacity: 0.5;
164+
}
165+
`;

src/mocks/__fixtures__/auth.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
export const authMockData = {
22
login: {
3-
"response": {
4-
"accessToken": "JWT 토큰 문자열",
5-
"refreshToken": "JWT 토큰 문자열"
3+
response: {
4+
accessToken: 'JWT 토큰 문자열',
5+
refreshToken: 'JWT 토큰 문자열',
66
},
7-
"code": "200",
8-
"message": "성공"
7+
code: '200',
8+
message: '성공',
9+
},
10+
logout: {
11+
code: '200',
12+
message: '성공',
913
},
1014
refresh: {
11-
"response": {
12-
"accessToken": "JWT 토큰 문자열",
13-
"refreshToken": "JWT 토큰 문자열"
15+
response: {
16+
accessToken: 'JWT 토큰 문자열',
17+
refreshToken: 'JWT 토큰 문자열',
1418
},
15-
"code": "200",
16-
"message": "성공"
17-
}
18-
}
19+
code: '200',
20+
message: '성공',
21+
},
22+
};

src/mocks/handlers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const authHandlers = [
1818
http.post(`${BASE_URL}/auth/refresh`, async () => {
1919
return HttpResponse.json(authMockData.refresh);
2020
}),
21+
http.post(`${BASE_URL}/auth/logout`, async () => {
22+
return HttpResponse.json(authMockData.logout);
23+
}),
2124
];
2225

2326
// 계정 관련 API 요청 핸들러 정의

src/pages/Signin/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ const SignIn = () => {
2424
resolver: zodResolver(loginSchema),
2525
});
2626

27-
const { login: loginFn } = useAuth(['admin', 'guest', 'owner']);
27+
const { login } = useAuth(['admin', 'guest', 'owner']);
28+
29+
const loginTestData = {
30+
accountId: 'test@naver.com',
31+
password: '123!@#',
32+
};
2833

2934
const onSubmit: SubmitHandler<SignInFormType> = async (data) => {
3035
try {
31-
await loginFn(data);
36+
if (
37+
data.accountId === loginTestData.accountId &&
38+
data.password === loginTestData.password
39+
) {
40+
await login(data);
41+
} else {
42+
alert('로그인 실패');
43+
}
3244
reset();
3345
} catch {
3446
alert('로그인 실패');

src/pages/store/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type { UpdateStorePayload } from 'api/modules/stores/types';
2424
import useAuth from 'common/hooks/useAuth';
2525

2626
const Store = ({ ...rest }) => {
27-
const { AuthGuard } = useAuth(['admin']);
27+
const { AuthGuard } = useAuth(['admin', 'owner']);
2828
const { data } = useGetStoresQueryTest(1);
2929
const { mutate: updateStoreQuery } = useUpdateStoresQuery();
3030

0 commit comments

Comments
 (0)