Refactor: 인증 흐름 개선 및 에러 메시지 통합
.vscode/settings.json - chatgpt 확장 자동 실행 비활성화 설정 추가 app/auth/callback/route.ts - OAuth 콜백 처리 개선: 에러 메시지 매핑 함수 사용 및 리다이렉트 로직 정리 app/auth/confirm/route.ts - 이메일 인증(토큰 검증) 라우트 신규 구현: recovery 쿠키 설정 및 안전한 리다이렉트 처리 app/forgot-password/page.tsx - UI 텍스트/플레이스홀더 정리, 메시지 렌더링 조건부 처리 app/reset-password/page.tsx - 리셋 페이지 접근/세션 검증 로직 정리 및 UI 문구/아이콘 변경 features/auth/actions.ts - 에러 처리 통합(getAuthErrorMessage 사용), 서버 액션 주석 정리 - 비밀번호 재설정 플로우 반환값을 객체로 변경하고 recovery 쿠키 삭제/로그아웃 처리 features/auth/components/reset-password-form.tsx - 클라이언트 폼: updatePassword 결과 처리 개선, 라우터 리다이렉션 및 에러 메시지 표시 개선 features/auth/constants.ts - 인증 관련 상수(에러 메시지, 코드/상태 매핑, 라우트, 검증 규칙, 쿠키 이름) 신규 추가 features/auth/errors.ts - Supabase Auth 에러를 한글 메시지로 변환하는 유틸 추가 features/auth/schemas/auth-schema.ts - zod 스키마 메시지 문구 정리 및 포맷 통일 utils/supabase/middleware.ts - 세션/쿠키 갱신 및 라우트 보호 로직 개선, recovery 쿠키 기반 리다이렉트 처리 추가 utils/supabase/server.ts - 서버용 Supabase 클라이언트 초기화 함수 추가 (쿠키 읽기/쓰기 처리)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"use client";
|
||||
"use client";
|
||||
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { updatePassword } from "@/features/auth/actions";
|
||||
import {
|
||||
resetPasswordSchema,
|
||||
@@ -13,22 +14,14 @@ import { Label } from "@/components/ui/label";
|
||||
import { InlineSpinner } from "@/components/ui/loading-spinner";
|
||||
import { useState } from "react";
|
||||
|
||||
/**
|
||||
* [비밀번호 재설정 폼 클라이언트 컴포넌트 - React Hook Form 버전]
|
||||
*
|
||||
* React Hook Form과 Zod를 사용한 비밀번호 재설정 폼입니다.
|
||||
* - 타입 안전한 폼 검증
|
||||
* - 비밀번호/비밀번호 확인 일치 검증
|
||||
* - 로딩 상태 표시
|
||||
*
|
||||
* @see app/reset-password/page.tsx - 이 컴포넌트를 사용하는 페이지
|
||||
*/
|
||||
const DEFAULT_ERROR_MESSAGE =
|
||||
"알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해 주세요.";
|
||||
|
||||
export default function ResetPasswordForm() {
|
||||
// ========== 로딩 상태 ==========
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [serverError, setServerError] = useState("");
|
||||
|
||||
// ========== React Hook Form 설정 ==========
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
@@ -39,11 +32,9 @@ export default function ResetPasswordForm() {
|
||||
mode: "onBlur",
|
||||
});
|
||||
|
||||
// 비밀번호 실시간 감시
|
||||
const password = watch("password");
|
||||
const confirmPassword = watch("confirmPassword");
|
||||
|
||||
// ========== 폼 제출 핸들러 ==========
|
||||
const onSubmit = async (data: ResetPasswordFormData) => {
|
||||
setServerError("");
|
||||
setIsLoading(true);
|
||||
@@ -52,10 +43,18 @@ export default function ResetPasswordForm() {
|
||||
const formData = new FormData();
|
||||
formData.append("password", data.password);
|
||||
|
||||
await updatePassword(formData);
|
||||
const result = await updatePassword(formData);
|
||||
|
||||
if (result?.ok) {
|
||||
const message = encodeURIComponent(result.message);
|
||||
router.replace(`/login?message=${message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
setServerError(result?.message || DEFAULT_ERROR_MESSAGE);
|
||||
} catch (error) {
|
||||
console.error("Password reset error:", error);
|
||||
setServerError("비밀번호 변경 중 오류가 발생했습니다.");
|
||||
setServerError(DEFAULT_ERROR_MESSAGE);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@@ -63,14 +62,12 @@ export default function ResetPasswordForm() {
|
||||
|
||||
return (
|
||||
<form className="space-y-5" onSubmit={handleSubmit(onSubmit)}>
|
||||
{/* ========== 서버 에러 메시지 표시 ========== */}
|
||||
{serverError && (
|
||||
<div className="rounded-md bg-red-50 p-3 text-sm text-red-700 dark:bg-red-900/50 dark:text-red-200">
|
||||
{serverError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ========== 새 비밀번호 입력 ========== */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password" className="text-sm font-medium">
|
||||
새 비밀번호
|
||||
@@ -78,14 +75,14 @@ export default function ResetPasswordForm() {
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
placeholder="••••••••"
|
||||
placeholder="새 비밀번호를 입력해주세요"
|
||||
autoComplete="new-password"
|
||||
disabled={isLoading}
|
||||
{...register("password")}
|
||||
className="h-11 transition-all duration-200"
|
||||
/>
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||
최소 8자 이상, 대문자, 소문자, 숫자, 특수문자 포함
|
||||
8자 이상, 대문자/소문자/숫자/특수문자를 각 1개 이상 포함해야 합니다.
|
||||
</p>
|
||||
{errors.password && (
|
||||
<p className="text-xs text-red-600 dark:text-red-400">
|
||||
@@ -94,37 +91,33 @@ export default function ResetPasswordForm() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ========== 비밀번호 확인 필드 ========== */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="confirmPassword" className="text-sm font-medium">
|
||||
비밀번호 확인
|
||||
새 비밀번호 확인
|
||||
</Label>
|
||||
<Input
|
||||
id="confirmPassword"
|
||||
type="password"
|
||||
placeholder="••••••••"
|
||||
placeholder="새 비밀번호를 다시 입력해주세요"
|
||||
autoComplete="new-password"
|
||||
disabled={isLoading}
|
||||
{...register("confirmPassword")}
|
||||
className="h-11 transition-all duration-200"
|
||||
/>
|
||||
{/* 비밀번호 불일치 시 실시간 피드백 */}
|
||||
{confirmPassword &&
|
||||
password !== confirmPassword &&
|
||||
!errors.confirmPassword && (
|
||||
<p className="text-xs text-red-600 dark:text-red-400">
|
||||
비밀번호가 일치하지 않습니다
|
||||
비밀번호가 일치하지 않습니다.
|
||||
</p>
|
||||
)}
|
||||
{/* 비밀번호 일치 시 확인 메시지 */}
|
||||
{confirmPassword &&
|
||||
password === confirmPassword &&
|
||||
!errors.confirmPassword && (
|
||||
<p className="text-xs text-green-600 dark:text-green-400">
|
||||
비밀번호가 일치합니다 ✓
|
||||
비밀번호가 일치합니다.
|
||||
</p>
|
||||
)}
|
||||
{/* Zod 검증 에러 */}
|
||||
{errors.confirmPassword && (
|
||||
<p className="text-xs text-red-600 dark:text-red-400">
|
||||
{errors.confirmPassword.message}
|
||||
@@ -132,7 +125,6 @@ export default function ResetPasswordForm() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ========== 비밀번호 변경 버튼 ========== */}
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
|
||||
Reference in New Issue
Block a user