-
Notifications
You must be signed in to change notification settings - Fork 37
[최성락] Sprint11 #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[최성락] Sprint11 #317
The head ref may contain hidden characters: "Next-\uCD5C\uC131\uB77D-sprint11"
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드도 너무 깔끔하고 일관되게 짜주셔서 보기도 너무 좋았습니다ㅎㅎ
그러다보니 리뷰할것도 별로 없었네요...;;ㅠ
잘 짜주셔서 감사합니다~!!
고생하셨구 멘토링떄 뵐게여ㅎㅎ
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
reset, | ||
} = useForm<LoginRequest>({ | ||
resolver: zodResolver(loginSchema), | ||
}); | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
await onSubmit({ email, password }); | ||
const onFormSubmit: SubmitHandler<LoginRequest> = async (data) => { | ||
try { | ||
await onSubmit(data); | ||
reset(); | ||
} catch (err) { | ||
console.error("서버오류", err); | ||
alert("로그인 중 오류가 발생했습니다. 다시 시도해주세요."); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 맞아요ㅎㅎ 이렇게 사용하는거에요.
엄청 잘 하셨는데여! 👍
useEffect(() => { | ||
if (typeof window !== "undefined") { | ||
const accessToken = localStorage.getItem("ACCESS_TOKEN_KEY"); | ||
if (accessToken) { | ||
router.replace("/"); | ||
} | ||
} | ||
}, [router]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미 useEffect에 왔다는거부터가 클라이언트 컴포넌트라서... window가 없을 수 없었을거에요ㅎㅎ;;
그래서 가급적이면 이런 redirect 처리는 서버쪽에서 처리해주는게 가장 좋아요~
accessToken: string; | ||
refreshToken: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 2개의 필드가 계속해서 나오는데, 차라리 인터페이스를 분리하고 합성해서 쓰는식은 어떨까요?
export interface AuthTokens {
accessToken: string;
refreshToken: string;
}
export interface SignupResponse extends AuthTokens {
user: {
id: number;
email: string;
image: null;
nickname: string;
updatedAt: string;
createdAt: string;
};
}
export interface LoginResponse extends AuthTokens {
user: {
id: number;
email: string;
image: null;
nickname: string;
updatedAt: string;
createdAt: string;
};
}
요구사항
회원가입
로그인
메인
주요 변경사항
멘토에게