summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-07 08:24:16 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-07 08:24:16 +0000
commit44bdb81a60d3a44ba7e379f3c20fe6d8fb284339 (patch)
treeb5c916a1c7ea37573f9bba7fefcef60a3b8aec20 /app
parent90f79a7a691943a496f67f01c1e493256070e4de (diff)
(대표님) 변경사항 20250707 12시 30분
Diffstat (limited to 'app')
-rw-r--r--app/[lng]/admin/mdg/page.tsx.bak (renamed from app/[lng]/admin/mdg/page.tsx)0
-rw-r--r--app/[lng]/admin/mdg/todo.md2
-rw-r--r--app/[lng]/evcp/(evcp)/login-history/page.tsx2
-rw-r--r--app/[lng]/evcp/(evcp)/page-visits/page.tsx61
-rw-r--r--app/[lng]/evcp/(evcp)/report/page.tsx69
-rw-r--r--app/api/auth/[...nextauth]/route.ts85
-rw-r--r--app/api/auth/first-auth/route.ts4
-rw-r--r--app/api/auth/send-sms/route.ts8
-rw-r--r--app/api/tracking/page-duration/route.ts56
-rw-r--r--app/api/tracking/page-visit/route.ts58
10 files changed, 256 insertions, 89 deletions
diff --git a/app/[lng]/admin/mdg/page.tsx b/app/[lng]/admin/mdg/page.tsx.bak
index e2926deb..e2926deb 100644
--- a/app/[lng]/admin/mdg/page.tsx
+++ b/app/[lng]/admin/mdg/page.tsx.bak
diff --git a/app/[lng]/admin/mdg/todo.md b/app/[lng]/admin/mdg/todo.md
new file mode 100644
index 00000000..497199a9
--- /dev/null
+++ b/app/[lng]/admin/mdg/todo.md
@@ -0,0 +1,2 @@
+라우터에서 [project] 세그먼트를 요구하는 문제가 있음
+이 페이지 수정 필요 ? \ No newline at end of file
diff --git a/app/[lng]/evcp/(evcp)/login-history/page.tsx b/app/[lng]/evcp/(evcp)/login-history/page.tsx
index af9c94f2..bd4d42cb 100644
--- a/app/[lng]/evcp/(evcp)/login-history/page.tsx
+++ b/app/[lng]/evcp/(evcp)/login-history/page.tsx
@@ -6,7 +6,6 @@ import { Skeleton } from "@/components/ui/skeleton"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import { Shell } from "@/components/shell"
-import { InformationButton } from "@/components/information/information-button"
import { getLoginSessions } from "@/lib/login-session/service"
import { searchParamsCache } from "@/lib/login-session/validation"
import { LoginSessionsTable } from "@/lib/login-session/table/login-sessions-table"
@@ -37,7 +36,6 @@ export default async function LoginHistoryPage(props: LoginHistoryPageProps) {
<h2 className="text-2xl font-bold tracking-tight">
로그인 세션 이력
</h2>
- <InformationButton pagePath="admin/sessions/login-history" />
</div>
<p className="text-muted-foreground">
사용자의 로그인/로그아웃 이력과 세션 정보를 확인할 수 있습니다.
diff --git a/app/[lng]/evcp/(evcp)/page-visits/page.tsx b/app/[lng]/evcp/(evcp)/page-visits/page.tsx
new file mode 100644
index 00000000..38386d51
--- /dev/null
+++ b/app/[lng]/evcp/(evcp)/page-visits/page.tsx
@@ -0,0 +1,61 @@
+import * as React from "react"
+import { type SearchParams } from "@/types/table"
+
+import { getValidFilters } from "@/lib/data-table"
+import { Skeleton } from "@/components/ui/skeleton"
+import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
+import { Shell } from "@/components/shell"
+import { getPageVisits } from "@/lib/page-visits/service"
+import { searchParamsCache } from "@/lib/page-visits/validation"
+import { PageVisitsTable } from "@/lib/page-visits/table/page-visits-table"
+
+interface PageVisitsPageProps {
+ searchParams: Promise<SearchParams>
+}
+
+export default async function PageVisitsPage(props: PageVisitsPageProps) {
+ const searchParams = await props.searchParams
+ const search = searchParamsCache.parse(searchParams)
+
+ const validFilters = getValidFilters(search.filters)
+
+ const promises = Promise.all([
+ getPageVisits({
+ ...search,
+ filters: validFilters,
+ }),
+ ])
+
+ return (
+ <Shell className="gap-2">
+ <div className="flex items-center justify-between space-y-2">
+ <div className="flex items-center justify-between space-y-2">
+ <div>
+ <div className="flex items-center gap-2">
+ <h2 className="text-2xl font-bold tracking-tight">
+ 페이지 방문 이력
+ </h2>
+ </div>
+ <p className="text-muted-foreground">
+ 사용자의 페이지별 방문 이력과 활동 패턴을 확인할 수 있습니다.
+ </p>
+ </div>
+ </div>
+ </div>
+
+ <React.Suspense
+ fallback={
+ <DataTableSkeleton
+ columnCount={9}
+ searchableColumnCount={2}
+ filterableColumnCount={4}
+ cellWidths={["10rem", "14rem", "20rem", "12rem", "10rem", "8rem", "10rem", "8rem", "8rem"]}
+ shrinkZero
+ />
+ }
+ >
+ <PageVisitsTable promises={promises} />
+ </React.Suspense>
+ </Shell>
+ )
+} \ No newline at end of file
diff --git a/app/[lng]/evcp/(evcp)/report/page.tsx b/app/[lng]/evcp/(evcp)/report/page.tsx
index f84ebe52..a538b37c 100644
--- a/app/[lng]/evcp/(evcp)/report/page.tsx
+++ b/app/[lng]/evcp/(evcp)/report/page.tsx
@@ -1,31 +1,38 @@
-// app/procurement/dashboard/page.tsx
import * as React from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { Shell } from "@/components/shell";
import { ErrorBoundary } from "@/components/error-boundary";
-import { getDashboardData, refreshDashboardData } from "@/lib/dashboard/service";
+import { getDashboardData } from "@/lib/dashboard/service";
import { DashboardClient } from "@/lib/dashboard/dashboard-client";
-export const dynamic = 'force-dynamic'; // ① 동적 페이지 선언
-
-// 대시보드 데이터 로딩 컴포넌트
-async function DashboardContent() {
+export default async function IndexPage() {
+ // domain을 명시적으로 전달
+ const domain = "evcp";
+
try {
- const data = await getDashboardData("evcp");
-
+ // 서버에서 직접 데이터 fetch
+ const dashboardData = await getDashboardData(domain);
+
return (
- <DashboardClient
- initialData={data}
- onRefresh={refreshDashboardData}
- />
+ <Shell className="gap-2">
+ <DashboardClient initialData={dashboardData} />
+ </Shell>
);
} catch (error) {
- console.error("Dashboard data loading error:", error);
- throw error;
+ console.error("Dashboard data fetch error:", error);
+ return (
+ <Shell className="gap-2">
+ <div className="flex items-center justify-center py-12">
+ <div className="text-center space-y-2">
+ <p className="text-destructive">데이터를 불러오는데 실패했습니다.</p>
+ <p className="text-muted-foregroucdnd text-sm">{error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다."}</p>
+ </div>
+ </div>
+ </Shell>
+ );
}
}
-// 대시보드 로딩 스켈레톤
function DashboardSkeleton() {
return (
<div className="space-y-6">
@@ -91,35 +98,3 @@ function DashboardSkeleton() {
</div>
);
}
-
-// 에러 표시 컴포넌트
-function DashboardError({ error, reset }: { error: Error; reset: () => void }) {
- return (
- <div className="flex flex-col items-center justify-center py-12 space-y-4">
- <div className="text-center space-y-2">
- <h3 className="text-lg font-semibold">대시보드를 불러올 수 없습니다</h3>
- <p className="text-muted-foreground">
- {error.message || "알 수 없는 오류가 발생했습니다."}
- </p>
- </div>
- <button
- onClick={reset}
- className="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
- >
- 다시 시도
- </button>
- </div>
- );
-}
-
-export default async function DashboardPage() {
- return (
- <Shell className="gap-6">
- <ErrorBoundary fallback={DashboardError}>
- <React.Suspense fallback={<DashboardSkeleton />}>
- <DashboardContent />
- </React.Suspense>
- </ErrorBoundary>
- </Shell>
- );
-} \ No newline at end of file
diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts
index 2b168746..e059377c 100644
--- a/app/api/auth/[...nextauth]/route.ts
+++ b/app/api/auth/[...nextauth]/route.ts
@@ -1,4 +1,3 @@
-// auth/config.ts - 업데이트된 NextAuth 설정
import NextAuth, {
NextAuthOptions,
Session,
@@ -14,16 +13,15 @@ import { verifyOtpTemp } from '@/lib/users/verifyOtp'
import { getSecuritySettings } from '@/lib/password-policy/service'
import { verifySmsToken } from '@/lib/users/auth/passwordUtil'
import { SessionRepository } from '@/lib/users/session/repository'
-import { loginSessions } from '@/db/schema'
// 인증 방식 타입 정의
type AuthMethod = 'otp' | 'email' | 'sgips' | 'saml'
-// 모듈 보강 선언 (기존과 동일)
+// 모듈 보강 선언 - ID를 string으로 통일
declare module "next-auth" {
interface Session {
user: {
- id: string
+ id: string // number → string으로 변경
name?: string | null
email?: string | null
image?: string | null
@@ -33,12 +31,12 @@ declare module "next-auth" {
reAuthTime?: number | null
authMethod?: AuthMethod
sessionExpiredAt?: number | null
- dbSessionId?: string | null // DB 세션 ID 추가
+ dbSessionId?: string | null
}
}
interface User {
- id: string
+ id: string // number → string으로 변경
imageUrl?: string | null
companyId?: number | null
techCompanyId?: number | null
@@ -51,7 +49,7 @@ declare module "next-auth" {
declare module "next-auth/jwt" {
interface JWT {
- id?: string
+ id?: string // 이미 string이므로 그대로
imageUrl?: string | null
companyId?: number | null
techCompanyId?: number | null
@@ -63,6 +61,15 @@ declare module "next-auth/jwt" {
}
}
+// 타입 변환 헬퍼 함수들
+function ensureString(value: string | number): string {
+ return String(value)
+}
+
+function ensureNumber(value: string | number): number {
+ return typeof value === 'string' ? parseInt(value, 10) : value
+}
+
// 보안 설정 캐시 (기존과 동일)
let securitySettingsCache: {
data: any | null
@@ -71,7 +78,7 @@ let securitySettingsCache: {
} = {
data: null,
lastFetch: 0,
- ttl: 5 * 60 * 1000 // 5분 캐시
+ ttl: 5 * 60 * 1000
}
async function getCachedSecuritySettings() {
@@ -85,7 +92,7 @@ async function getCachedSecuritySettings() {
} catch (error) {
console.error('Failed to fetch security settings:', error)
securitySettingsCache.data = {
- sessionTimeoutMinutes: 480 // 8시간 기본값
+ sessionTimeoutMinutes: 480
}
}
}
@@ -111,7 +118,7 @@ function getClientIP(req: any): string {
export const authOptions: NextAuthOptions = {
providers: [
- // OTP 로그인 (기존 유지)
+ // OTP 로그인 - 타입 에러 수정
CredentialsProvider({
id: 'credentials-otp',
name: 'OTP',
@@ -130,8 +137,9 @@ export const authOptions: NextAuthOptions = {
const securitySettings = await getCachedSecuritySettings()
const reAuthTime = Date.now()
+ // 반환 객체의 id를 string으로 변환
return {
- id: String(user.id ?? email ?? "dts"),
+ id: ensureString(user.id), // ✅ string으로 변환
email: user.email,
imageUrl: user.imageUrl ?? null,
name: user.name,
@@ -144,12 +152,12 @@ export const authOptions: NextAuthOptions = {
},
}),
- // MFA 완료 후 최종 인증 (DB 연동 버전)
+ // MFA 완료 후 최종 인증 - 타입 에러 수정
CredentialsProvider({
id: 'credentials-mfa',
name: 'MFA Verification',
credentials: {
- userId: { label: 'User ID', type: 'text' },
+ userId: { label: 'User ID', type: 'text' }, // number → text로 변경
smsToken: { label: 'SMS Token', type: 'text' },
tempAuthKey: { label: 'Temp Auth Key', type: 'text' },
},
@@ -159,28 +167,29 @@ export const authOptions: NextAuthOptions = {
return null
}
+ // userId를 number로 변환하여 DB 조회
+ const numericUserId = ensureNumber(credentials.userId)
+ const user = await getUserById(numericUserId)
+ if (!user) {
+ console.error('User not found after MFA verification')
+ return null
+ }
+
try {
// DB에서 임시 인증 정보 확인
const tempAuth = await SessionRepository.getTempAuthSession(credentials.tempAuthKey)
- if (!tempAuth || tempAuth.userId !== credentials.userId) {
+ if (!tempAuth || ensureNumber(tempAuth.userId) !== user.id) {
console.error('Temp auth expired or not found')
return null
}
// SMS 토큰 검증
- const smsVerificationResult = await verifySmsToken(Number(credentials.userId), credentials.smsToken)
+ const smsVerificationResult = await verifySmsToken(user.id, credentials.smsToken)
if (!smsVerificationResult || !smsVerificationResult.success) {
console.error('SMS token verification failed')
return null
}
- // 사용자 정보 조회
- const user = await getUserById(Number(credentials.userId))
- if (!user) {
- console.error('User not found after MFA verification')
- return null
- }
-
// 임시 인증 정보를 사용됨으로 표시
await SessionRepository.markTempAuthSessionAsUsed(credentials.tempAuthKey)
@@ -194,7 +203,7 @@ export const authOptions: NextAuthOptions = {
const userAgent = req.headers?.['user-agent']
const dbSession = await SessionRepository.createLoginSession({
- userId: String(user.id),
+ userId: user.id, // number로 전달
ipAddress,
userAgent,
authMethod: tempAuth.authMethod,
@@ -203,8 +212,9 @@ export const authOptions: NextAuthOptions = {
console.log(`MFA completed for user ${user.email} (${tempAuth.authMethod})`)
+ // 반환 객체의 id를 string으로 변환
return {
- id: String(user.id),
+ id: ensureString(user.id), // ✅ string으로 변환
email: user.email,
imageUrl: user.imageUrl ?? null,
name: user.name,
@@ -257,7 +267,7 @@ export const authOptions: NextAuthOptions = {
session: {
strategy: 'jwt',
- maxAge: 30 * 24 * 60 * 60, // 30일
+ maxAge: 30 * 24 * 60 * 60,
},
callbacks: {
@@ -268,7 +278,7 @@ export const authOptions: NextAuthOptions = {
// 최초 로그인 시 (MFA 완료 후)
if (user) {
const reAuthTime = Date.now()
- token.id = user.id
+ token.id = user.id // ✅ 이제 둘 다 string 타입
token.email = user.email
token.name = user.name
token.companyId = user.companyId
@@ -288,8 +298,8 @@ export const authOptions: NextAuthOptions = {
try {
const dbSession = await SessionRepository.createLoginSession({
- userId: token.id,
- ipAddress: '0.0.0.0', // SAML의 경우 IP 추적 제한적
+ userId: ensureNumber(token.id), // string을 number로 변환하여 DB에 저장
+ ipAddress: '0.0.0.0',
authMethod: 'saml',
sessionExpiredAt,
})
@@ -346,7 +356,7 @@ export const authOptions: NextAuthOptions = {
if (token) {
session.user = {
- id: token.id as string,
+ id: token.id as string, // ✅ string으로 일관성 유지
email: token.email as string,
name: token.name as string,
domain: token.domain as string,
@@ -386,14 +396,16 @@ export const authOptions: NextAuthOptions = {
// 이미 MFA에서 DB 세션이 생성된 경우가 아니라면 여기서 생성
if (account?.provider !== 'credentials-mfa' && user.id) {
try {
+ const numericUserId = ensureNumber(user.id) // string을 number로 변환
+
// 기존 활성 세션 확인
- const existingSession = await SessionRepository.getActiveSessionByUserId(user.id)
+ const existingSession = await SessionRepository.getActiveSessionByUserId(numericUserId)
if (!existingSession) {
const sessionExpiredAt = new Date(Date.now() + (securitySettings.sessionTimeoutMinutes * 60 * 1000))
await SessionRepository.createLoginSession({
- userId: user.id,
- ipAddress: '0.0.0.0', // signIn 이벤트에서는 IP 접근 제한적
+ userId: numericUserId,
+ ipAddress: '0.0.0.0',
authMethod: user.authMethod || 'unknown',
sessionExpiredAt,
})
@@ -415,8 +427,15 @@ export const authOptions: NextAuthOptions = {
await SessionRepository.logoutSession(dbSessionId)
} else if (userId) {
// dbSessionId가 없는 경우 사용자의 모든 활성 세션 로그아웃
- await SessionRepository.logoutAllUserSessions(userId)
+ const numericUserId = ensureNumber(userId) // string을 number로 변환
+ await SessionRepository.logoutAllUserSessions(numericUserId)
}
}
}
}
+
+
+const handler = NextAuth(authOptions)
+
+// ✅ 핵심: 반드시 GET, POST를 named export로 내보내야 함
+export { handler as GET, handler as POST } \ No newline at end of file
diff --git a/app/api/auth/first-auth/route.ts b/app/api/auth/first-auth/route.ts
index 18f44904..ff92e71c 100644
--- a/app/api/auth/first-auth/route.ts
+++ b/app/api/auth/first-auth/route.ts
@@ -1,8 +1,8 @@
// /api/auth/first-auth/route.ts
// 1차 인증 처리 API 엔드포인트
+import { authHelpers } from '@/lib/users/session/helper'
import { NextRequest, NextResponse } from 'next/server'
-import { authHelpers } from '../[...nextauth]/route'
// 요청 데이터 타입
interface FirstAuthRequest {
@@ -15,7 +15,7 @@ interface FirstAuthRequest {
interface FirstAuthResponse {
success: boolean
tempAuthKey?: string
- userId?: string
+ userId?: number
email?: string
error?: string
}
diff --git a/app/api/auth/send-sms/route.ts b/app/api/auth/send-sms/route.ts
index 6b9eb114..805ff7f7 100644
--- a/app/api/auth/send-sms/route.ts
+++ b/app/api/auth/send-sms/route.ts
@@ -2,13 +2,11 @@
import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
-import { getServerSession } from 'next-auth';
-import { authOptions } from '@/app/api/auth/[...nextauth]/route';
-import { getUserByEmail, getUserById } from '@/lib/users/repository';
+import { getUserById } from '@/lib/users/repository';
import { generateAndSendSmsToken } from '@/lib/users/auth/passwordUtil';
const sendSmsSchema = z.object({
- userId: z.string(),
+ userId: z.number(),
});
export async function POST(request: NextRequest) {
@@ -28,7 +26,7 @@ export async function POST(request: NextRequest) {
}
// 사용자 정보 조회
- const user = await getUserById(Number(userId));
+ const user = await getUserById(userId);
if (!user || !user.phone) {
return NextResponse.json(
{ error: '전화번호가 등록되지 않았습니다' },
diff --git a/app/api/tracking/page-duration/route.ts b/app/api/tracking/page-duration/route.ts
new file mode 100644
index 00000000..861a52cc
--- /dev/null
+++ b/app/api/tracking/page-duration/route.ts
@@ -0,0 +1,56 @@
+import { NextRequest, NextResponse } from 'next/server'
+import { getServerSession } from 'next-auth'
+import db from '@/db/db'
+import { pageVisits } from '@/db/schema'
+import { and, eq, desc, gte } from 'drizzle-orm'
+import { authOptions } from '../../auth/[...nextauth]/route'
+
+// 타입 변환 헬퍼
+function ensureNumber(value: string | number): number {
+ return typeof value === 'string' ? parseInt(value, 10) : value
+ }
+
+ export async function POST(request: NextRequest) {
+ try {
+ const session = await getServerSession(authOptions)
+ const { route, duration, timestamp } = await request.json()
+
+ // 세션이 있는 경우에만 체류 시간 업데이트
+ if (session?.user?.id) {
+ // string ID를 number로 변환
+ const numericUserId = ensureNumber(session.user.id)
+
+ // 최근 5분 내의 해당 라우트 방문 기록을 찾아서 체류 시간 업데이트
+ const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000)
+
+ // 방법 1: 서브쿼리를 사용해서 가장 최근 레코드의 ID를 찾아서 업데이트
+ const latestVisitSubquery = db
+ .select({ id: pageVisits.id })
+ .from(pageVisits)
+ .where(
+ and(
+ eq(pageVisits.userId, numericUserId), // ✅ 이제 타입 매칭
+ eq(pageVisits.route, route),
+ gte(pageVisits.visitedAt, fiveMinutesAgo)
+ )
+ )
+ .orderBy(desc(pageVisits.visitedAt))
+ .limit(1)
+
+ // 서브쿼리 결과를 사용해서 업데이트
+ const latestVisit = await latestVisitSubquery
+
+ if (latestVisit.length > 0) {
+ await db
+ .update(pageVisits)
+ .set({ duration })
+ .where(eq(pageVisits.id, latestVisit[0].id))
+ }
+ }
+
+ return NextResponse.json({ success: true })
+ } catch (error) {
+ console.error('Page duration tracking API error:', error)
+ return NextResponse.json({ success: false }, { status: 200 })
+ }
+ } \ No newline at end of file
diff --git a/app/api/tracking/page-visit/route.ts b/app/api/tracking/page-visit/route.ts
new file mode 100644
index 00000000..26263b04
--- /dev/null
+++ b/app/api/tracking/page-visit/route.ts
@@ -0,0 +1,58 @@
+import { NextRequest, NextResponse } from 'next/server'
+import { getServerSession } from 'next-auth'
+import { SessionRepository } from '@/lib/users/session/repository'
+import { authOptions } from '../../auth/[...nextauth]/route'
+
+function ensureNumber(value: string | number): number {
+ return typeof value === 'string' ? parseInt(value, 10) : value
+}
+export async function POST(request: NextRequest) {
+ try {
+ const session = await getServerSession(authOptions)
+ const trackingData = await request.json()
+
+ // IP 주소 추출
+ const getClientIP = (req: NextRequest): string => {
+ const forwarded = req.headers.get('x-forwarded-for')
+ const realIP = req.headers.get('x-real-ip')
+ const cfConnectingIP = req.headers.get('cf-connecting-ip')
+
+ if (cfConnectingIP) return cfConnectingIP
+ if (forwarded) return forwarded.split(',')[0].trim()
+ if (realIP) return realIP
+ return '127.0.0.1'
+ }
+
+ // 활성 세션 조회 및 업데이트
+ let sessionId = null
+ if (session?.user?.id && session?.user?.dbSessionId) {
+ sessionId = session.user.dbSessionId
+
+ // 세션 활동 시간 업데이트 (백그라운드)
+ SessionRepository.updateSessionActivity(sessionId).catch(error => {
+ console.error('Failed to update session activity:', error)
+ })
+ }
+
+ // 페이지 방문 기록
+ await SessionRepository.recordPageVisit({
+ userId: session?.user?.id ? ensureNumber(session.user.id) : undefined, // ✅ 타입 변환
+ sessionId,
+ route: trackingData.route,
+ pageTitle: trackingData.pageTitle || undefined,
+ referrer: trackingData.referrer || undefined,
+ ipAddress: getClientIP(request),
+ userAgent: trackingData.userAgent,
+ queryParams: new URL(request.url).search || undefined,
+ deviceType: trackingData.deviceType || undefined,
+ browserName: trackingData.browserName || undefined,
+ osName: trackingData.osName || undefined,
+ })
+
+ return NextResponse.json({ success: true })
+ } catch (error) {
+ console.error('Page visit tracking API error:', error)
+ // 추적 실패가 클라이언트에 영향을 주지 않도록 성공 응답
+ return NextResponse.json({ success: false }, { status: 200 })
+ }
+} \ No newline at end of file