Skip to content

Commit

Permalink
fix: 로그인 시 로그인, 회원가입 페이지에 접근 불가능하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsdncl committed Jun 14, 2024
1 parent b6c14a3 commit 84e8289
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
18 changes: 1 addition & 17 deletions src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import {
getAccessToken,
setAccessToken,
setRefreshToken,
clearTokens,
getRefreshToken,
} from '../Utils/TokenManager';
import { refreshAccessToken } from '../api/Auth.api';
import instance from '../api/Axios';

const SignIn: React.FC = () => {
const [email, setEmail] = useState('');
Expand Down Expand Up @@ -45,21 +43,7 @@ const SignIn: React.FC = () => {
}

if (accessToken) {
try {
// 사용자 정보 가져오기
const response = await instance.get('/api/user-info', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
if (response.status === 200) {
console.log('User is logged in:', response.data);
navigate('/');
}
} catch (error) {
console.error('Auto login failed:', error);
clearTokens();
}
navigate('/');
}
};
autoLogin();
Expand Down
9 changes: 9 additions & 0 deletions src/pages/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import PasswordInputField from '../components/Sign/PasswordInputField';
import SocialSignIn from '../components/Sign/SocialSignIn';
import { PostSignUp } from '../api/Validator.api';
import { useNavigate } from 'react-router';
import { getAccessToken } from 'Utils/TokenManager';

const SignUp: React.FC = () => {
const [email, setEmail] = useState('');
Expand All @@ -31,6 +32,14 @@ const SignUp: React.FC = () => {

const navigate = useNavigate();

useEffect(() => {
const accessToken = getAccessToken();

if (accessToken) {
navigate('/');
}
}, [navigate]);

// 입력 필드 검증 함수
const validateField = (name: string, value: string) => {
let error = '';
Expand Down

0 comments on commit 84e8289

Please sign in to comment.