Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@ import { auth, signIn } from "@/lib/auth";
import { Button } from "@/components/ui/button";

type LoginPageProps = {
searchParams: Promise<{ callbackUrl?: string }>;
searchParams: Promise<{ callbackUrl?: string; error?: string }>;
};

function getAuthErrorMessage(error?: string) {
switch (error) {
case "AccessDenied":
return "SNU 구글 계정이 아니거나 이메일 인증이 완료되지 않아 로그인할 수 없습니다.";
case "Configuration":
return "서버의 Google 로그인 설정 또는 외부 연결 상태를 확인해야 합니다.";
case "OAuthCallback":
case "OAuthSignin":
return "Google 로그인 처리 중 문제가 발생했습니다. 잠시 후 다시 시도하세요.";
case undefined:
return null;
default:
return "로그인에 실패했습니다. 다시 시도해도 반복되면 서버 로그를 확인하세요.";
}
}

export default async function LoginPage({ searchParams }: LoginPageProps) {
const session = await auth();
if (session?.user) {
redirect(session.user.approved ? "/" : "/pending");
}

const { callbackUrl } = await searchParams;
const { callbackUrl, error } = await searchParams;
const callback = callbackUrl ?? "/";
const errorMessage = getAuthErrorMessage(error);

async function signInWithGoogle() {
"use server";
Expand All @@ -32,6 +49,12 @@ export default async function LoginPage({ searchParams }: LoginPageProps) {
</p>
</div>

{errorMessage ? (
<div className="w-full rounded-md border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-destructive">
{errorMessage}
</div>
) : null}

<form action={signInWithGoogle} className="w-full">
<Button type="submit" className="w-full" size="lg">
SNU 구글로 계속하기
Expand Down
1 change: 1 addition & 0 deletions auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const authConfig = {
],
pages: {
signIn: "/login",
error: "/login",
},
callbacks: {
// signIn callback 의 도메인 검증은 server-only (DB 안 건드리지만 안전하게 lib/auth 에 둔다).
Expand Down
Loading