251121_01_ENH : 로그인 및 인증 저장, api통신 시 자동으로 accessKey 붙게 조치
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
const MainLayout = ({ children }: { children: React.ReactNode}) => {
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col">
|
||||
{/* 공통 헤더 */}
|
||||
<header className="h-14 border-b px-4 flex items-center">
|
||||
<h1 className="font-semibold">Contact Admin</h1>
|
||||
</header>
|
||||
|
||||
{/* 메인 컨텐츠 영역 */}
|
||||
<main className="flex-1 flex">
|
||||
{/* 필요하면 사이드바 */}
|
||||
{/* <aside className="w-60 border-r">사이드바</aside> */}
|
||||
|
||||
<section className="flex-1 p-4">{children}</section>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MainLayout;
|
||||
@@ -1,8 +0,0 @@
|
||||
const ListPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is List Page</div>)
|
||||
}
|
||||
|
||||
export default ListPage;
|
||||
@@ -1,8 +0,0 @@
|
||||
const UserPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is User Page</div>)
|
||||
}
|
||||
|
||||
export default UserPage;
|
||||
8
src/app/(pages)/(main)/assign/list/page.tsx
Normal file
8
src/app/(pages)/(main)/assign/list/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const ListAssignPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is List Assign Page</div>)
|
||||
}
|
||||
|
||||
export default ListAssignPage;
|
||||
8
src/app/(pages)/(main)/assign/project/page.tsx
Normal file
8
src/app/(pages)/(main)/assign/project/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const ProjectAssignPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Project Assign Page</div>)
|
||||
}
|
||||
|
||||
export default ProjectAssignPage;
|
||||
40
src/app/(pages)/(main)/layout.tsx
Normal file
40
src/app/(pages)/(main)/layout.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import MainLayout from "@/components/layout/MainLayout";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import {CookieKeys} from "@/store/cookie/cookie-keys";
|
||||
import commonConst from "@/config/commonConst";
|
||||
|
||||
function parseFontSize(raw: string | undefined | null) {
|
||||
if (!raw) return commonConst.fontSizeMin;
|
||||
|
||||
const parsed = parseInt(raw, 10);
|
||||
if (Number.isNaN(parsed)) return commonConst.fontSizeMin;
|
||||
|
||||
return Math.min(
|
||||
commonConst.fontSizeMax,
|
||||
Math.max(commonConst.fontSizeMin, parsed),
|
||||
);
|
||||
}
|
||||
|
||||
export default async function MainLayoutWrapper({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const cookieStore = await cookies();
|
||||
const cookie = cookieStore.get(CookieKeys.FontSize);
|
||||
const accessToken = cookieStore.get("access_token")?.value;
|
||||
const initialFontSize = parseFontSize(cookie?.value);
|
||||
|
||||
if (!accessToken) {
|
||||
redirect("/logout");
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<MainLayout initialFontSize={initialFontSize}>
|
||||
{children}
|
||||
</MainLayout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
8
src/app/(pages)/(main)/list/contact/page.tsx
Normal file
8
src/app/(pages)/(main)/list/contact/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const ListContactPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is List Contact Page</div>)
|
||||
}
|
||||
|
||||
export default ListContactPage;
|
||||
21
src/app/(pages)/(main)/list/manage/page.tsx
Normal file
21
src/app/(pages)/(main)/list/manage/page.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import {useFontSizeValue} from "@/hooks/useFontSize";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
const ListManagePage = () => {
|
||||
const fontSize = useFontSizeValue();
|
||||
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => setMounted(true), []);
|
||||
if (!mounted) return null;
|
||||
|
||||
return (
|
||||
<div>
|
||||
This is Manage List Page <span>{fontSize}</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ListManagePage;
|
||||
8
src/app/(pages)/(main)/manage/user/page.tsx
Normal file
8
src/app/(pages)/(main)/manage/user/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const UserManagePage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is User Manage Page</div>)
|
||||
}
|
||||
|
||||
export default UserManagePage;
|
||||
9
src/app/(pages)/(main)/message/template/email/page.tsx
Normal file
9
src/app/(pages)/(main)/message/template/email/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
const EmailTemplatePage = () => {
|
||||
//파라미터 받기
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Email Template Page</div>)
|
||||
}
|
||||
|
||||
export default EmailTemplatePage;
|
||||
9
src/app/(pages)/(main)/message/template/text/page.tsx
Normal file
9
src/app/(pages)/(main)/message/template/text/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
const TextTemplatePage = () => {
|
||||
//파라미터 받기
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Text Message Template Page</div>)
|
||||
}
|
||||
|
||||
export default TextTemplatePage;
|
||||
8
src/app/(pages)/(main)/progress/contact/page.tsx
Normal file
8
src/app/(pages)/(main)/progress/contact/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const ContactProgressPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Contact Progress Page</div>)
|
||||
}
|
||||
|
||||
export default ContactProgressPage;
|
||||
8
src/app/(pages)/(main)/progress/fieldwork/page.tsx
Normal file
8
src/app/(pages)/(main)/progress/fieldwork/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const FieldworkProgressPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Fieldwork Progress Page</div>)
|
||||
}
|
||||
|
||||
export default FieldworkProgressPage;
|
||||
8
src/app/(pages)/(main)/progress/message/page.tsx
Normal file
8
src/app/(pages)/(main)/progress/message/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const MessageProgressPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Message Progress Page</div>)
|
||||
}
|
||||
|
||||
export default MessageProgressPage;
|
||||
8
src/app/(pages)/(main)/project/info/page.tsx
Normal file
8
src/app/(pages)/(main)/project/info/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
const ProjectInfoPage = () => {
|
||||
//const url = buildUrlWithParams("/login", searchParams, { ref: "root" });
|
||||
//redirect(url);
|
||||
|
||||
return (<div>This is Project Info Page</div>)
|
||||
}
|
||||
|
||||
export default ProjectInfoPage;
|
||||
209
src/app/(pages)/login/page.tsx
Normal file
209
src/app/(pages)/login/page.tsx
Normal file
@@ -0,0 +1,209 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Card, CardContent, CardHeader} from "@/components/ui/card";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import React, {useEffect, useRef, useState} from "react";
|
||||
import {HttpError, nextApi} from "@/lib/http-client";
|
||||
import {useRouter, useSearchParams} from "next/navigation";
|
||||
import {LoginUser} from "@/types/auth";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useLoading } from "@/hooks/useLoading";
|
||||
import { useStorage } from "@/hooks/useStorage"
|
||||
import { StorageKeys } from "@/store/storage/storage-keys";
|
||||
|
||||
const LoginPage = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { setFromLoginResponse } = useAuth();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const { get: getSeatNumberStorage, set: setSeatNumberStorage } = useStorage(StorageKeys.SeatNumber);
|
||||
const { get: getLoginTypeStorage, set: setLoginTypeStorage } = useStorage(StorageKeys.LoginType);
|
||||
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [userId, setUserId] = useState<string>("");
|
||||
const [userPw, setUserPw] = useState<string>("");
|
||||
const [seatNum, setSeatNum] = useState<string>(getSeatNumberStorage());
|
||||
const [loginType, setLoginType] = useState<string>(getLoginTypeStorage());
|
||||
|
||||
const passwordInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const seatNumberInputRef = useRef<HTMLInputElement | null>(null);
|
||||
|
||||
const tryLogin = () => {
|
||||
if(!userId){
|
||||
alert("아이디를 입력해 주세요");
|
||||
}
|
||||
if(!userPw){
|
||||
alert("PW를 입력해 주세요");
|
||||
}
|
||||
if(loginType === "call" && !seatNum){
|
||||
alert("자리번호를 입력해 주세요");
|
||||
}
|
||||
|
||||
setError(null);
|
||||
const loginRequestBody = {userId, userPw};
|
||||
const loginRequestOptions = {autoLogoutOnAuthError: false};
|
||||
|
||||
// withLoading 래퍼로 API 호출 전/후 로딩 표시를 자동으로 처리
|
||||
return withLoadingAsync(() =>
|
||||
nextApi.post<LoginUser>(
|
||||
"/api/login", loginRequestBody, loginRequestOptions
|
||||
).then(async (data) => { // Jotai 기반 전역 인증 상태 갱신
|
||||
setFromLoginResponse(data, seatNum);
|
||||
// 요구사항: 페이지 이동 전에 SeatNumber를 secure-local-storage에 저장
|
||||
try {
|
||||
setSeatNumberStorage(seatNum);
|
||||
setLoginTypeStorage(loginType);
|
||||
} catch (e) {
|
||||
// 저장 실패는 치명적이지 않으므로 콘솔 로깅만
|
||||
console.warn("Failed to persist SeatNumber to secure storage:", e);
|
||||
}
|
||||
// 메인 페이지로 이동 (보호 라우트 진입)
|
||||
router.replace("/");
|
||||
}).catch((err) => {
|
||||
if (err instanceof HttpError) {
|
||||
if (err.status === 401 || err.status === 403) {
|
||||
setError("아이디 또는 비밀번호를 다시 확인해주세요.");
|
||||
} else {
|
||||
setError(`로그인에 실패했습니다. (status: ${err.status})`);
|
||||
}
|
||||
} else {
|
||||
console.error(err);
|
||||
setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// URL 쿼리 파라미터에서 type 수신
|
||||
useEffect(() => {
|
||||
const typeParam = searchParams.get("type") ?? "";
|
||||
let seatNumTemp = "";
|
||||
|
||||
if(typeParam === "call") {
|
||||
seatNumTemp = getSeatNumberStorage();
|
||||
}
|
||||
setSeatNum(seatNumTemp);
|
||||
setLoginType(typeParam);
|
||||
}, [searchParams]);
|
||||
|
||||
const handleIdKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
passwordInputRef.current?.focus();
|
||||
}
|
||||
};
|
||||
|
||||
const handlePwKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
const seatNumberInput = seatNumberInputRef.current;
|
||||
if(loginType === "call" && seatNumberInput?.value === ""){
|
||||
seatNumberInput.focus();
|
||||
}
|
||||
else{
|
||||
tryLogin();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleSeatNumberKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
tryLogin();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 p-4">
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="space-y-4 pb-8">
|
||||
<div className="flex justify-center">
|
||||
<div className="w-60 h-32 flex items-center justify-center">
|
||||
<Image
|
||||
src="/kri_logo.png" // public/kri_logo.png
|
||||
alt="KRI 로고"
|
||||
width={500} // 원하는 크기로 줄이기
|
||||
height={500}
|
||||
className="object-contain ml-10"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">ID</label>
|
||||
<Input
|
||||
id="id"
|
||||
name="id"
|
||||
type="text"
|
||||
required
|
||||
placeholder="아이디를 입력하세요"
|
||||
value={userId}
|
||||
onChange={(e) => setUserId(e.currentTarget.value)}
|
||||
onKeyDown={handleIdKeyDown}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Password</label>
|
||||
<Input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
placeholder="PW를 입력하세요"
|
||||
value={userPw}
|
||||
onChange={(e) => setUserPw(e.currentTarget.value)}
|
||||
onKeyDown={handlePwKeyDown}
|
||||
ref={passwordInputRef}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{loginType === "call"?
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">자리번호 (면접원)</label>
|
||||
<Input
|
||||
id="seatNum"
|
||||
name="seatNum"
|
||||
type="text"
|
||||
placeholder="자리번호를 입력하세요"
|
||||
value={seatNum}
|
||||
onChange={(e) => setSeatNum(e.currentTarget.value)}
|
||||
onKeyDown={handleSeatNumberKeyDown}
|
||||
ref={seatNumberInputRef}
|
||||
/>
|
||||
</div>
|
||||
:
|
||||
null
|
||||
}
|
||||
|
||||
{error && (
|
||||
<p className="text-sm text-red-500">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full mt-6 h-11"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
tryLogin();
|
||||
}}
|
||||
>
|
||||
로그인
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoginPage;
|
||||
42
src/app/(pages)/logout/page.tsx
Normal file
42
src/app/(pages)/logout/page.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
'use client'
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {useStorage} from "@/hooks/useStorage";
|
||||
import {StorageKeys} from "@/store/storage/storage-keys";
|
||||
import {useEffect} from "react";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
|
||||
const LogoutPage = () => {
|
||||
const { get: getLoginTypeStorage, set: setLoginTypeStorage } = useStorage(StorageKeys.LoginType);
|
||||
const { logout } = useAuth();
|
||||
const { clearSelectedProject } = useSelectedProject();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const runLogout = async () => {
|
||||
clearSelectedProject();
|
||||
logout();
|
||||
|
||||
try {
|
||||
await nextApi.del("/api/logout", {});
|
||||
} catch (e) {
|
||||
console.error("로그아웃 API 호출 실패", e);
|
||||
}
|
||||
|
||||
const loginType = getLoginTypeStorage();
|
||||
const loginUrl = loginType === "call" ? "/login?type=call" : "/login";
|
||||
|
||||
router.replace(loginUrl);
|
||||
};
|
||||
|
||||
withLoadingAsync(runLogout);
|
||||
}, []);
|
||||
|
||||
// Nothing to render while redirecting
|
||||
return null;
|
||||
}
|
||||
|
||||
export default LogoutPage;
|
||||
@@ -1,24 +1,37 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { intranetApi } from "@/api/auth";
|
||||
import {LoginRequest} from "@/types/auth";
|
||||
import {LoginRequest, LoginUser} from "@/types/auth";
|
||||
import {serverEnv} from "@/lib/env.server";
|
||||
import {createContactApi} from "@/lib/server-api";
|
||||
|
||||
//실제 Backend
|
||||
type LoginResponse = {
|
||||
accessToken: string;
|
||||
user: LoginUser;
|
||||
};
|
||||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
try {
|
||||
const body = (await req.json()) as LoginRequest;
|
||||
const result = await intranetApi.login({
|
||||
userId: body.userId,
|
||||
userPw: body.userPw,
|
||||
});
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
const body = (await req.json()) as LoginRequest;
|
||||
const result = await contactApi.post<LoginResponse>("/auth/login", body);
|
||||
|
||||
const res = NextResponse.json(result.user, { status: 200 });
|
||||
res.cookies.set("access_token", result.accessToken, {
|
||||
httpOnly: true,
|
||||
secure: serverEnv.ENV === "prod",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
maxAge: 24 * 60 * 60, // 24시간
|
||||
});
|
||||
|
||||
return res;
|
||||
} catch (error : unknown) {
|
||||
console.error("login error:", error);
|
||||
const err = error as { status?: number; data?: unknown };
|
||||
const status = typeof err.status === "number" ? err.status : 500;
|
||||
const payload = err.data !== undefined ? err.data : { message: "서버에서 오류 응답을 받았습니다." };
|
||||
|
||||
const err = error as { status?: number; data?: unknown };
|
||||
const status = typeof err.status === "number" ? err.status : 500;
|
||||
const payload = err.data !== undefined ? err.data : { message: "서버에서 오류 응답을 받았습니다." };
|
||||
|
||||
return NextResponse.json(payload, { status });
|
||||
return NextResponse.json(payload, { status });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
src/app/api/logout/route.ts
Normal file
16
src/app/api/logout/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import {serverEnv} from "@/lib/env.server";
|
||||
|
||||
export async function DELETE() {
|
||||
const res = NextResponse.json({ ok: true });
|
||||
|
||||
res.cookies.set("access_token", "", {
|
||||
httpOnly: true,
|
||||
secure: serverEnv.ENV === "prod",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
maxAge: 0,
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
5
src/app/api/project/route.ts
Normal file
5
src/app/api/project/route.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import {NextRequest} from "next/server";
|
||||
|
||||
export const GET = async (req: NextRequest) => {
|
||||
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 15 KiB |
@@ -1,5 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import {Geist, Geist_Mono} from "next/font/google";
|
||||
import { AppProvider } from "@/components/providers/AppProvider";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
@@ -13,17 +14,17 @@ const geistMono = Geist_Mono({
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Contact",
|
||||
description: "Contact system",
|
||||
title: "KRI Contact",
|
||||
description: "KRI Contact 시스템",
|
||||
};
|
||||
|
||||
const RootLayout = ({ children }: { children: React.ReactNode}) => {
|
||||
return (
|
||||
<html lang="ko">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
{children}
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
<AppProvider>{children}</AppProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Card, CardContent, CardHeader} from "@/components/ui/card";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import {MouseEventHandler, useState} from "react";
|
||||
import {HttpError, nextApi} from "@/lib/http-client";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {LoginResponse} from "@/types/auth";
|
||||
|
||||
const LoginPage = () => {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [userId, setUserId] = useState<string>("");
|
||||
const [userPw, setUserPw] = useState<string>("");
|
||||
const [seatNum, setSeatNum] = useState<string>("");
|
||||
|
||||
const tryLogin = () => {
|
||||
setError(null);
|
||||
setIsLoading(true);
|
||||
|
||||
const data = nextApi.post<LoginResponse>("/api/login", {
|
||||
userId,
|
||||
userPw,
|
||||
}).then((data) => {
|
||||
console.log(data)
|
||||
|
||||
// 🔐 토큰 저장 예시 (실제에선 cookie, secure storage 등으로 변경 가능)
|
||||
/*if (typeof window !== "undefined") {
|
||||
localStorage.setItem("accessToken", data.accessToken);
|
||||
}*/
|
||||
|
||||
// 로그인 성공 후 메인으로 이동 (원하는 경로로 변경)
|
||||
//router.push("/");
|
||||
}).catch((err) => {
|
||||
if (err instanceof HttpError) {
|
||||
if (err.status === 401) {
|
||||
setError("이메일 또는 비밀번호를 다시 확인해주세요.");
|
||||
} else {
|
||||
setError(`로그인에 실패했습니다. (status: ${err.status})`);
|
||||
}
|
||||
} else {
|
||||
console.error(err);
|
||||
setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 p-4">
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="space-y-4 pb-8">
|
||||
<div className="flex justify-center">
|
||||
<div className="w-32 h-32 bg-blue-600 rounded-2xl flex items-center justify-center">
|
||||
<span className="text-white text-4xl font-bold">LOGO</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">ID</label>
|
||||
<Input
|
||||
id="id"
|
||||
name="id"
|
||||
type="text"
|
||||
required
|
||||
placeholder="아이디를 입력하세요"
|
||||
value={userId}
|
||||
onChange={(e) => setUserId(e.currentTarget.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Password</label>
|
||||
<Input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
placeholder="••••••••"
|
||||
value={userPw}
|
||||
onChange={(e) => setUserPw(e.currentTarget.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">자리번호 (면접원)</label>
|
||||
<Input
|
||||
id="seatNum"
|
||||
name="seatNum"
|
||||
type="text"
|
||||
placeholder="자리번호를 입력하세요"
|
||||
value={seatNum}
|
||||
onChange={(e) => setSeatNum(e.currentTarget.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="text-sm text-red-500">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full mt-6 h-11"
|
||||
disabled={isLoading}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
tryLogin();
|
||||
}}
|
||||
>
|
||||
{isLoading ? "로그인 중..." : "로그인"}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoginPage;
|
||||
@@ -1,7 +0,0 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
const LogoutPage = () => {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
export default LogoutPage;
|
||||
Reference in New Issue
Block a user