로그인 성공시 /workspace/channel 로 이동이 안되고 있습니다.
569
작성한 질문수 0
App.tsx
import React, { FC } from 'react';
import loadable from '@loadable/component';
import { Switch, Route, Redirect } from 'react-router';
const Login = loadable(() => import('@pages/Login'));
const SignUp = loadable(() => import('@pages/SignUp'));
const Channel = loadable(() => import('@pages/Channel'));
const App: FC = () => {
return (
<Switch>
<Redirect exact path="/" to="/login" />
<Route path="/login" component={Login} />
<Route path="/signUp" component={SignUp} />
<Route path="/workspace/channel" component={Channel} />
</Switch>
);
};
export default App;
Login/ index.tsx
import React, { useState, useCallback } from 'react';
import useInput from '@pages/hooks/useinput';
import axios from 'axios';
import { Error, Form, Label, Input, LinkContainer, Button, Header } from '@pages/SignUp/styles';
import { Link, Redirect } from 'react-router-dom';
import useSWR from 'swr';
import fetcher from '@utils/fetcher';
const Login = () => {
const { data, error, revalidate } = useSWR('http://localhost:3095/api/users', fetcher);
//주소를 fetcher로 옮겨주고 실제로 주소를 어떻게 처리할지 정해줌
const [logInError, setLogInError] = useState(false);
const [email, onChangeEmail] = useInput('');
const [password, onChangePassword] = useInput('');
const onSubmit = useCallback(
(e) => {
e.preventDefault();
setLogInError(false);
axios
.post(
'http://localhost:3095/api/users/login',
{ email, password },
{
withCredentials: true,
},
)
.then(() => {
revalidate();
})
.catch((error) => {
setLogInError(error.response?.data?.statusCode === 401);
});
},
[email, password],
);
if (data) {
return <Redirect to="/workspace/channel" />;
}Channel / index.tsx
import Workspace from '@layouts/Workspace';
import React from 'react';
const Channel = () => {
return (
<Workspace>
<div>로그인을 축하합니다.</div>
</Workspace>
);
};
export default Channel;
Workspace.tsx
import React, { FC, useCallback } from 'react';
import useSWR from 'swr';
import fetcher from '@utils/fetcher';
import axios from 'axios';
import { Redirect } from 'react-router';
const Workspace: FC = ({ children }) => {
const { data, error, revalidate } = useSWR('http://localhost:3095/api/users', fetcher);
const onLogout = useCallback(() => {
axios
.post('http://localhost:3095/api/users/logout', null, {
withCredentials: true,
})
.then(() => {
revalidate();
});
}, []);
if (!data) {
return <Redirect to="/login" />;
}
return (
<div>
<button onClick={onLogout}>로그아웃</button>
{children}
</div>
);
};
export default Workspace;
현재 코드에서 로그인 성공까지 되는데 페이지 이동이 없습니다... 하나하나 빠짐없이 확인 해봤는데 제가 찾지 못하는거 같습니다 ㅠㅠ
더군다나 URl 주소를 다이렉트로 localhost:3090/workspace/channel 입력해도 아무런 창이 뜨지 않고 있어서 어떤 문제가 있는지 확인이 어렵습니다.. 도움을 부탁드려요
답변 2
0
말씀 주신 부분을 수정후에는 URL로 강제 진입은 성공했습니다.
그러고 쿠키를 삭제하고 난 뒤에 로그인 버튼을 눌렀을 때 응답은 잘 오고 있는데 redirect가 반응을 하지 않아 화면 전환이 되지 않고 있습니다..
0
일단 콘솔 탭에 에러는 없나요?
localhost:3090/signup 입력하면 회원가입 페이지는 뜨나요?
0
회원가입 페이지는 잘 뜨고 있습니다.
그리고 workspace/channel 의 콘솔창에는
p://localhost:3090/workspace/dist/app.js net::ERR_ABORTED 404 (Not Found)
channel:1 Refused to execute script from 'http://localhost:3090/workspace/dist/app.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
channel:40 GET https://a.slack-edge.com/bv1-8/slack-icons-v2-40cccfd.woff2 net::ERR_ABORTED 403
channel:33 GET https://a.slack-edge.com/bv1-8/client-boot-styles.57e47b5.css 403이러한 에러가 표시되고 있습니다.
기본 셋팅과 관련하여
0
92
1
초기 셋팅 back과 front만 남겨두고 다 지운 후 진행 방법
0
96
2
focus 시에만 화면 업데이트 되는 이유 + 해결방법
0
150
2
useEffect 개수 관리
0
110
2
라이브러리 서치 방법
0
104
2
함수 정의 패턴
0
77
1
npm run dev 에러
0
152
3
npx webpack 후 에러
0
178
2
'void' 형식 식의 truthiness를 테스트할 수 없습니다.ts(1345)
0
144
2
사용자 가입시 에러발생 (TypeError: Cannot read properties of null (reading 'addMembers')
1
178
2
초기세팅중 packge.json 에러떠요
0
156
2
CORS - Access-Control-Allow-Origin 누락 문제
0
431
3
로그인 페이지 무한 새로고침 현상
0
598
2
Module not found: Error: Can't resolve './App' 에러
0
959
1
배포 방법
0
298
2
npm run dev 시 빌드가 매우 느려졌습니다
0
990
2
alias 경로 설정 오류
0
452
2
fetcher 함수의 data 값이 두번 찍히는 이유
0
278
1
제네릭 질문
0
218
2
ts-node 대신 tsx 사용여부
0
373
1
배포 관련 질문
0
247
1
[nginx + https] 서비스를 실행하면 niginx가 아닌 서비스 화면을 보여주게 하고 싶습니다.
0
385
2
[배포하기] webpack에 aws 퍼블릭 IPv4 주소 와 포트 주소를 작성하고 나서 빌드후 실행하면 오류가 발생합니다.
0
336
1
users 호출 시 쿠키가 담기지 않는 이슈 질문드립니다.
0
247
2





