.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 클라이언트 초기화 함수 추가 (쿠키 읽기/쓰기 처리)
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import { createClient } from "@/utils/supabase/server";
|
|
import { NextResponse } from "next/server";
|
|
import { AUTH_ERROR_MESSAGES, AUTH_ROUTES } from "@/features/auth/constants";
|
|
import { getAuthErrorMessage } from "@/features/auth/errors";
|
|
|
|
/**
|
|
* OAuth/??? ?? ?? ??
|
|
*/
|
|
export async function GET(request: Request) {
|
|
const { searchParams, origin } = new URL(request.url);
|
|
|
|
const code = searchParams.get("code");
|
|
const next = searchParams.get("next") ?? AUTH_ROUTES.HOME;
|
|
const error = searchParams.get("error");
|
|
const error_code = searchParams.get("error_code");
|
|
const error_description = searchParams.get("error_description");
|
|
|
|
if (error) {
|
|
console.error("Auth callback error parameter:", {
|
|
error,
|
|
error_code,
|
|
error_description,
|
|
});
|
|
|
|
let message: string = AUTH_ERROR_MESSAGES.DEFAULT;
|
|
|
|
if (error === "access_denied") {
|
|
message = AUTH_ERROR_MESSAGES.OAUTH_ACCESS_DENIED;
|
|
} else if (error === "server_error") {
|
|
message = AUTH_ERROR_MESSAGES.OAUTH_SERVER_ERROR;
|
|
}
|
|
|
|
return NextResponse.redirect(
|
|
`${origin}${AUTH_ROUTES.LOGIN}?message=${encodeURIComponent(message)}`,
|
|
);
|
|
}
|
|
|
|
if (code) {
|
|
const supabase = await createClient();
|
|
const { error: exchangeError } =
|
|
await supabase.auth.exchangeCodeForSession(code);
|
|
|
|
if (!exchangeError) {
|
|
const forwardedHost = request.headers.get("x-forwarded-host");
|
|
const isLocalEnv = process.env.NODE_ENV === "development";
|
|
|
|
if (isLocalEnv) {
|
|
return NextResponse.redirect(`${origin}${next}`);
|
|
}
|
|
|
|
if (forwardedHost) {
|
|
return NextResponse.redirect(`https://${forwardedHost}${next}`);
|
|
}
|
|
|
|
return NextResponse.redirect(`${origin}${next}`);
|
|
}
|
|
|
|
console.error("Auth exchange error:", exchangeError.message);
|
|
const message = getAuthErrorMessage(exchangeError);
|
|
return NextResponse.redirect(
|
|
`${origin}${AUTH_ROUTES.LOGIN}?message=${encodeURIComponent(message)}`,
|
|
);
|
|
}
|
|
|
|
const errorMessage = encodeURIComponent(
|
|
AUTH_ERROR_MESSAGES.INVALID_AUTH_LINK,
|
|
);
|
|
return NextResponse.redirect(
|
|
`${origin}${AUTH_ROUTES.LOGIN}?message=${errorMessage}`,
|
|
);
|
|
}
|