Skip to content

Commit

Permalink
Merge pull request #111 from woohaengshi/59-feature-sign-in-up-api
Browse files Browse the repository at this point in the history
[feat/#59]: 로그인 후 라우팅 수정
  • Loading branch information
riverkite0708 authored Aug 28, 2024
2 parents 612e01c + 5aa727c commit c10516d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
14 changes: 2 additions & 12 deletions components/auth/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface LoginFormProps {
export default function LoginForm({ onLogin }: LoginFormProps) {
const [email, setEmail] = useState<string>('');
const [password, setPassword] = useState<string>('');
const router = useRouter();

const handleLogin = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
Expand All @@ -36,21 +35,12 @@ export default function LoginForm({ onLogin }: LoginFormProps) {
} else {
setEmail('');
setPassword('');
router.push('/study');

window.location.href = '/study';
alert('로그인에 성공했습니다.');
}
};

// 유저정보조회
const accessToken = Cookies.get('access_token');
const { setUserInfo } = useUserInfoStore();
const { data } = useSWR(accessToken ? ['userInfo'] : null, async () => {
const result = await getUserInfo();
const storedUserInfo = { name: result.name, course: result.course, image: result.image };
localStorage.setItem('userInfo', JSON.stringify(storedUserInfo));
setUserInfo(storedUserInfo);
});

return (
<AuthFormLayout title="로그인">
<form onSubmit={handleLogin}>
Expand Down
13 changes: 13 additions & 0 deletions components/study/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { useSubjectStore } from '@/store/subjectStore';
import Cookies from 'js-cookie';
import { ErrorResponse } from '@/types/commonType';
import { postTimer } from '@/api/studyApi';
import { useUserInfoStore } from '@/store/memberStore';
import useSWR from 'swr';
import { getUserInfo } from '@/api/memberApi';

interface ITimer {
maxTime: number;
Expand All @@ -28,6 +31,16 @@ export default function Timer({ maxTime, currentTime }: ITimer) {
const [progress, setProgress] = useState((currentTime / maxTime) * 100);
const [remainingTime, setRemainingTime] = useState(maxTime - (currentTime % maxTime));

// 유저정보조회
const accessToken = Cookies.get('access_token');
const { setUserInfo } = useUserInfoStore();
const { data } = useSWR(accessToken ? ['userInfo'] : null, async () => {
const result = await getUserInfo();
const storedUserInfo = { name: result.name, course: result.course, image: result.image };
localStorage.setItem('userInfo', JSON.stringify(storedUserInfo));
setUserInfo(storedUserInfo);
});

const startTimeRef = useRef<number | null>(null);
const animationFrameRef = useRef<number | null>(null);
const lastSaveDateRef = useRef<string | null>(null); // 마지막 저장 날짜 -> 중복 저장 방지
Expand Down

0 comments on commit c10516d

Please sign in to comment.