Skip to content

Commit 0db42d4

Browse files
committed
feat: 인증 모달 API 연결
1 parent ae86c6a commit 0db42d4

File tree

6 files changed

+54
-19
lines changed

6 files changed

+54
-19
lines changed

public/assets/icons/loading.svg

+24
Loading

src/components/atoms/ModalButton/index.jsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ import PropTypes from 'prop-types';
22

33
import { Wrapper } from './styles';
44

5-
function ModalButton({ children, type }) {
6-
return <Wrapper type={type}>{children}</Wrapper>;
5+
function ModalButton({ children, type, isLoading }) {
6+
return (
7+
<Wrapper type={type} isLoading={isLoading}>
8+
{children}
9+
</Wrapper>
10+
);
711
}
812

913
ModalButton.propTypes = {
1014
children: PropTypes.node.isRequired,
1115
type: PropTypes.node,
16+
isLoading: PropTypes.bool,
1217
};
1318

1419
ModalButton.defaultProps = {
1520
type: 'button',
21+
isLoading: false,
1622
};
1723

1824
export default ModalButton;

src/components/atoms/ModalButton/styles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const Wrapper = styled.button`
44
align-self: center;
55
background: transparent;
66
height: 60px;
7-
width: 168px;
7+
width: ${({ isLoading }) => (isLoading ? '60px' : '168px')};
88
padding: 0 24px;
99
margin: 28px 0;
1010
border: none;

src/components/atoms/ModalInput/index.jsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import PropTypes from 'prop-types';
22

33
import { Input } from './styles';
44

5-
function ModalInput({ type, placeholder, autoFocus, name }) {
6-
return <Input type={type} placeholder={placeholder} autoFocus={autoFocus} name={name} />;
5+
function ModalInput({ type, placeholder, autoFocus, name, value }) {
6+
return (
7+
<Input type={type} placeholder={placeholder} autoFocus={autoFocus} name={name} value={value} />
8+
);
79
}
810

911
ModalInput.propTypes = {
1012
type: PropTypes.string.isRequired,
1113
placeholder: PropTypes.string.isRequired,
1214
autoFocus: PropTypes.bool,
1315
name: PropTypes.string,
16+
value: PropTypes.string,
1417
};
1518

1619
ModalInput.defaultProps = {
1720
autoFocus: false,
1821
name: '',
22+
value: '',
1923
};
2024

2125
export default ModalInput;

src/components/molecules/AuthModal/index.jsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ import { Form, Title } from './styles';
1212

1313
function AuthModal() {
1414
const [isAuthModalShow, setIsAuthModalShow] = useRecoilState(isAuthModalShowAtom);
15-
const mutation = useMutation(({ email, password }) =>
16-
axios.post('api/sign-in', { email, password }),
15+
const { mutate, isLoading } = useMutation(
16+
({ email, password }) => axios.post('api/sign-in', { email, password }),
17+
{
18+
onSuccess: () => setIsAuthModalShow(false),
19+
},
1720
);
1821

1922
const signIn = (event) => {
2023
event.preventDefault();
2124
const formData = new FormData(event.target);
2225
const data = Object.fromEntries(formData);
23-
mutation.mutate(data);
26+
mutate(data);
2427
};
2528

2629
return (
27-
<ModalBase
28-
isVisible={isAuthModalShow}
29-
onClose={() => {
30-
setIsAuthModalShow(false);
31-
}}
32-
>
30+
<ModalBase isVisible={isAuthModalShow} onClose={() => setIsAuthModalShow(false)}>
3331
<Form onSubmit={signIn}>
3432
<Title>Welcome</Title>
35-
<ModalInput type='email' placeholder='Email' autoFocus name='email' value='' />
33+
<ModalInput type='email' placeholder='Email' autoFocus name='email' />
3634
<ModalInput type='password' placeholder='Password' name='password' />
37-
<ModalButton type='submit'>Sign in</ModalButton>
35+
<ModalButton type='submit' isLoading={isLoading}>
36+
Sign in
37+
</ModalButton>
3838
</Form>
3939
</ModalBase>
4040
);

src/pages/api/sign-in.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import axios from 'axios';
22

3+
const url = 'https://auth.kalgory.com/sign-in';
34
async function handler(req, res) {
4-
const { email: id, password } = req.body;
5-
await axios.post('https://auth.kalgory.com/sign-in', { id, password });
6-
res.status(200).json({ name: 'John Doe' });
5+
const response = await axios.post(url, req.body);
6+
res.setHeader('set-cookie', response.headers['set-cookie']);
7+
res.status(response.status).end();
78
}
89

910
export default handler;

0 commit comments

Comments
 (0)