아이디,비번 작성후 로그인이되지 않습니다.
424
작성한 질문수 15
리덕스 적용 후 아이디,비번값 넣고 로그인버튼 누르면 로그인된 화면으로 넘어가질 않습니다. 버튼이 동작하지 않습니다 ㅠㅠ 콘솔과 코드 보여드릴게요ㅠㅠ
콘솔
LoginForm.js
import React, { useCallback, useState } from "react";
import Link from "next/link";
import { Form, Input, Button } from "antd";
import styled from "styled-components";
import { useDispatch } from "react-redux";
import useInput from "../hooks/useInput";
import { loginAction } from "../reducers";
const LoginForm = () => {
const dispatch = useDispatch();
const [id, onChangeId] = useInput("");
const [password, setPassword] = useState("");
const FormWrapper = styled(Form)`
padding: 10px !important;
`;
const onChangePassword = useCallback((e) => {
setPassword(e.target.value);
}, []);
const onSubmitForm = useCallback(() => {
dispatch(loginAction({ id, password }));
}, [id, password]);
return (
<FormWrapper onFinish={onSubmitForm}>
<div>
<label htmlFor="user-id">아이디</label>
<Input name="user-id" value={id} onChange={onChangeId} required></Input>
</div>
<div>
<label htmlFor="user-password">비밀번호</label>
<Input
name="user-password"
value={password}
onChange={onChangePassword}
required
></Input>
</div>
<div style={{ maringTop: "10px" }}>
<Button type="primary" htmlType="submit" loading={false}>
로그인
</Button>
<Link href="/signup">
<a>회원가입</a>
</Link>
</div>
</FormWrapper>
);
};
export default LoginForm;
AppLayout.js
import React from "react";
import PropTypes from "prop-types";
import Link from "next/link";
import { Menu, Input, Row, Col } from "antd";
import UserProfile from "../components/UserProfile";
import LoginForm from "../components/LoginForm";
import { useSelector } from "react-redux";
const AppLayout = ({ children }) => {
const isLoggedIn = useSelector((state) => {
state.user.isLoggedIn;
});
return (
<div>
<Menu mode="horizontal">
<Menu.Item key="/">
<Link href="/">
<a>메인</a>
</Link>
</Menu.Item>
<Menu.Item key="/profile">
<Link href="/profile">
<a>프로필</a>
</Link>
</Menu.Item>
<Menu.Item key="mail">
<Input.Search enterButton style={{ verticalAlign: "middle" }} />
</Menu.Item>
<Menu.Item key="/signup">
<Link href="/signup">
<a>회원가입</a>
</Link>
</Menu.Item>
</Menu>
<Row gutter={8}>
<Col xs={24} md={6}>
{isLoggedIn ? <UserProfile /> : <LoginForm />}
</Col>
<Col xs={24} md={12}>
{children}
</Col>
<Col xs={24} md={6}>
<a
href="https://github.com/wejunguk"
target="_blank"
rel="noreferrer noopener"
>
github by
</a>
</Col>
</Row>
</div>
);
};
AppLayout.propTypes = {
children: PropTypes.node.isRequired,
};
export default AppLayout;
index.js
import { HYDRATE } from "next-redux-wrapper";
const initialState = {
user: {
isLoggedIn: false,
user: null,
signUpData: {},
loginData: {},
},
post: {
mainPosts: [],
},
};
export const loginAction = (data) => {
return {
type: "LOG_IN",
data,
};
};
export const logoutAction = () => {
return {
type: "LOG_OUT",
};
};
const rootReducer = (state = initialState, action) => {
switch (action.type) {
case HYDRATE:
console.log("HYDRATE", action);
return {
...state,
...action.payload,
};
case "LOG_IN":
return {
...state,
user: {
...state.user,
isLoggedIn: true,
user: action.data,
},
};
case "LOG_OUT":
return {
...state,
user: {
...state.user,
isLoggedIn: false,
user: null,
},
};
default:
return state;
}
};
export default rootReducer;
configureStore.js
import { createWrapper } from "next-redux-wrapper";
import { createStore } from "redux";
import reducer from "../reducers";
const configureStore = () => {
const store = createStore(reducer);
return store;
};
const wrapper = createWrapper(configureStore, {
debug: process.env.NODE_ENV === "development",
});
export default wrapper;
답변 1
1
const isLoggedIn = useSelector((state) => state.user.isLoggedIn);
오타입니다. { } 가 있는 것과 없는 것은 천지차이입니다.
넥스트 버젼 질문
0
79
2
로그인시 401 Unauthorized 오류가 뜹니다
0
91
1
무한 스크롤 중 스크롤 튐 현상
0
177
1
특정 페이지 접근을 막고 싶을 때
0
105
2
createGlobalStyle의 위치와 영향범위
0
97
2
인라인 스타일 리렌더링 관련
0
93
2
vsc 에서 npm init 설치시 오류
0
149
2
nextjs 15버전 사용 가능할까요?
0
160
1
화면 새로고침 문의
0
123
1
RTK에서 draft, state 차이가 있나요?
0
156
2
Next 14 사용해도 될까요?
0
452
1
next, node 버전 / 폴더 구조 질문 드립니다.
0
350
1
url 오류 질문있습니다
0
211
1
ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out
0
379
1
sudo certbot --nginx 에러
0
1282
2
Minified React error 콘솔에러 (hydrate)
0
471
1
카카오 공유했을 때 이전에 작성했던 글이 나오는 버그
0
249
1
프론트서버 배포 후 EADDRINUSE에러 발생
0
329
1
npm run build 에러
0
519
1
front 서버 npm run build 중에 발생한 에러들
0
383
1
서버 실행하고 브라우저로 들어갔을때 404에러
0
339
2
css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.
0
289
1
팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.
0
242
2
해시태그 검색에서 throttle에 관해 질문있습니다.
0
202
1





