From e66b009dd3f377ab9fb92ef7bda417aa337c2840 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 11:16:47 +0900 Subject: [PATCH 1/8] fix: Update session data display in Header component to use store name instead of category; add additional role mapping in README --- README.md | 3 ++- src/components/ui/common/Header.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72a29f7..6d332e0 100644 --- a/README.md +++ b/README.md @@ -54,12 +54,13 @@ session에 있는 role 키로 구분한다 session.role === 'Admin_Sub' - constA03_01 / 1234 -> 시공사\ session.role === 'Builder' +- teshg44 / 1234 -> 시공사\ + session.role === 'Builder' - partners -> Q.Partners 계정\ session.role === 'Partner' - 이외의 경우 -> 굳이 체크할 필요 없어보임\ session.role === 'User' - # 지붕재 적합성 TODO ``` diff --git a/src/components/ui/common/Header.tsx b/src/components/ui/common/Header.tsx index 3a2ca15..bd92675 100644 --- a/src/components/ui/common/Header.tsx +++ b/src/components/ui/common/Header.tsx @@ -71,7 +71,7 @@ export default function Header() {
{session.userNm}
-
{session.category}
+
{session.storeNm}
From 4e8f698f88e25c7e844aa4784b28da4cfe39d223 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 11:17:14 +0900 Subject: [PATCH 2/8] feat: Integrate tracking functionality in authentication API routes for enhanced user activity monitoring; update tracking data structure in tracking route --- src/app/api/auth/logout/route.ts | 7 +++++++ src/app/api/auth/route.ts | 8 ++++++++ src/app/api/tracking/route.ts | 24 ++++++++++++++++-------- src/libs/axios.ts | 3 +-- src/providers/EdgeProvider.tsx | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/app/api/auth/logout/route.ts b/src/app/api/auth/logout/route.ts index 78f0a58..ad4b365 100644 --- a/src/app/api/auth/logout/route.ts +++ b/src/app/api/auth/logout/route.ts @@ -3,11 +3,18 @@ import { cookies } from 'next/headers' import { NextResponse } from 'next/server' import { getIronSession } from 'iron-session' import { sessionOptions } from '@/libs/session' +import { tracking } from '@/libs/tracking' export async function GET(request: Request) { const cookieStore = await cookies() const session = await getIronSession(cookieStore, sessionOptions) + tracking({ + url: '/api/auth/logout', + data: JSON.stringify({ + userId: session.userId, + }), + }) session.destroy() // return redirect('/login') diff --git a/src/app/api/auth/route.ts b/src/app/api/auth/route.ts index c595ecd..d5149a9 100644 --- a/src/app/api/auth/route.ts +++ b/src/app/api/auth/route.ts @@ -4,6 +4,7 @@ import { NextResponse } from 'next/server' import { getIronSession } from 'iron-session' import { axiosInstance } from '@/libs/axios' import { sessionOptions } from '@/libs/session' +import { tracking } from '@/libs/tracking' export async function POST(request: Request) { const { loginId, pwd } = await request.json() @@ -15,6 +16,13 @@ export async function POST(request: Request) { console.log('🚀 ~ result ~ result:', result.data) if (result.data.result.code === 200) { + tracking({ + url: `/api/auth/login`, + data: JSON.stringify({ + loginId, + pwd, + }), + }) const cookieStore = await cookies() const session = await getIronSession(cookieStore, sessionOptions) diff --git a/src/app/api/tracking/route.ts b/src/app/api/tracking/route.ts index d5f5607..913b4c5 100644 --- a/src/app/api/tracking/route.ts +++ b/src/app/api/tracking/route.ts @@ -1,17 +1,25 @@ import type { SessionData } from '@/types/Auth' import { NextResponse } from 'next/server' import { cookies } from 'next/headers' -import { Prisma } from '@prisma/client' +import { prisma } from '@/libs/prisma' import { getIronSession } from 'iron-session' import { sessionOptions } from '@/libs/session' -export const POST = async (request: Request) => { +export async function POST(request: Request) { const { url, data } = await request.json() const cookieStore = await cookies() const session = await getIronSession(cookieStore, sessionOptions) - let owner = session.userId + let owner = '' + if (url === '/api/auth/login') { + owner = 'Login' + } else if (url === '/api/auth/logout') { + owner = 'Logout' + } else { + owner = session.userId ?? 'Direct' + } + let type = '' if (url.includes('api')) { type = 'api' @@ -20,12 +28,12 @@ export const POST = async (request: Request) => { } // @ts-ignore - const result = await Prisma.MS_USR_TRK.create({ + const result = await prisma.MS_USR_TRK.create({ data: { - owner, - type, - url, - data: JSON.stringify(data), + OWNER: owner, + TYPE: type, + URL: url, + DATA: JSON.stringify(data), }, }) diff --git a/src/libs/axios.ts b/src/libs/axios.ts index b75e989..0abc6ab 100644 --- a/src/libs/axios.ts +++ b/src/libs/axios.ts @@ -1,5 +1,4 @@ import axios from 'axios' -import { tracking } from './tracking' export const axiosInstance = (url: string | null | undefined) => { const baseURL = url || process.env.NEXT_PUBLIC_API_URL @@ -12,7 +11,7 @@ export const axiosInstance = (url: string | null | undefined) => { instance.interceptors.request.use( (config) => { - console.log('🚀 ~ config:', config) + // console.log('🚀 ~ config:', config) return config }, (error) => { diff --git a/src/providers/EdgeProvider.tsx b/src/providers/EdgeProvider.tsx index de3c00f..7bba179 100644 --- a/src/providers/EdgeProvider.tsx +++ b/src/providers/EdgeProvider.tsx @@ -108,7 +108,7 @@ export default function EdgeProvider({ children, sessionData }: EdgeProviderProp //사이드바 초기화 reset() // 페이지 이벤트 트래킹 - // handlePageEvent(pathname) + handlePageEvent(pathname) }, [pathname]) return <>{children} From 45f523447a103e38aa21fa4598436ae852c3bc4d Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 11:31:19 +0900 Subject: [PATCH 3/8] feat: Add email validation in Login component and implement database connection utility; enhance login logic with partner status check --- src/components/Login.tsx | 15 ++++++++++++++- src/libs/{partner.tsx => partner.ts} | 0 2 files changed, 14 insertions(+), 1 deletion(-) rename src/libs/{partner.tsx => partner.ts} (100%) diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 24b7219..6322ec4 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -33,6 +33,11 @@ export default function Login() { pwd: '', }) + const isValidEmail = (email: string) => { + const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ + return emailRegex.test(email) + } + interface LoginData { code: number message: string | null @@ -82,6 +87,14 @@ export default function Login() { } }, [loginData]) + useEffect(() => { + if (isValidEmail(account.loginId)) { + setIsPartners(true) + } else { + setIsPartners(false) + } + }, [account.loginId]) + return ( <>
@@ -94,7 +107,7 @@ export default function Login() { value={account.loginId} onChange={(e) => setAccount({ loginId: e.target.value })} /> -
diff --git a/src/libs/partner.tsx b/src/libs/partner.ts similarity index 100% rename from src/libs/partner.tsx rename to src/libs/partner.ts From dd34c51dc167cf945c5056f30e230600a01dbbf5 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 11:33:18 +0900 Subject: [PATCH 4/8] refactor: Remove console log from tracking function to clean up output and improve code clarity --- src/libs/tracking.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/tracking.ts b/src/libs/tracking.ts index 1fc2d06..2f8833f 100644 --- a/src/libs/tracking.ts +++ b/src/libs/tracking.ts @@ -6,5 +6,4 @@ export const tracking = async (params: { url: string; data: string }) => { url, data, }) - console.log('🚀 ~ result ~ result:', result) } From 0d96d4928109b4ff90550dd7be005995a4cd57a8 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 13:26:59 +0900 Subject: [PATCH 5/8] refactor: Update BC_COMM_H model fields to be optional for improved flexibility in data handling --- prisma/schema.prisma | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e2d5cc1..00e4bc6 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -122,28 +122,28 @@ model SD_SURVEY_SALES_DETAIL_INFO { model BC_COMM_H { HEAD_CD String @id(map: "PK_BC_COMM_H") @db.NVarChar(6) - HEAD_ID String @db.NVarChar(100) - HEAD_NM String @db.NVarChar(100) - HEAD_JP String @db.NVarChar(100) - HEAD_4TH String @db.NVarChar(100) - REF_CHR1 String @db.NVarChar(100) - REF_CHR2 String @db.NVarChar(100) - REF_CHR3 String @db.NVarChar(100) - REF_CHR4 String @db.NVarChar(100) - REF_CHR5 String @db.NVarChar(100) - REF_NUM1 String @db.NVarChar(100) - REF_NUM2 String @db.NVarChar(100) - REF_NUM3 String @db.NVarChar(100) - REF_NUM4 String @db.NVarChar(100) - REF_NUM5 String @db.NVarChar(100) - REMARKS String @db.NVarChar(200) - SAP_YN String @db.NVarChar(1) - STAT_CD String @db.NVarChar(1) - DEL_YN String @db.NVarChar(1) + HEAD_ID String? @db.NVarChar(100) + HEAD_NM String? @db.NVarChar(100) + HEAD_JP String? @db.NVarChar(100) + HEAD_4TH String? @db.NVarChar(100) + REF_CHR1 String? @db.NVarChar(100) + REF_CHR2 String? @db.NVarChar(100) + REF_CHR3 String? @db.NVarChar(100) + REF_CHR4 String? @db.NVarChar(100) + REF_CHR5 String? @db.NVarChar(100) + REF_NUM1 String? @db.NVarChar(100) + REF_NUM2 String? @db.NVarChar(100) + REF_NUM3 String? @db.NVarChar(100) + REF_NUM4 String? @db.NVarChar(100) + REF_NUM5 String? @db.NVarChar(100) + REMARKS String? @db.NVarChar(200) + SAP_YN String? @db.NVarChar(1) + STAT_CD String? @db.NVarChar(1) + DEL_YN String? @db.NVarChar(1) REG_DT DateTime? @db.DateTime - REG_ID String @db.NVarChar(50) + REG_ID String? @db.NVarChar(50) UPT_DT DateTime? @db.DateTime - UPT_ID String @db.NVarChar(50) + UPT_ID String? @db.NVarChar(50) QC_COMM_YN String? @default("N", map: "DF__BC_COMM_H__QC_CO__48CFD27E") @db.NVarChar(1) BC_COMM_L BC_COMM_L[] From ac59d626ab919cdbf62985442aa59f57bd75fa06 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 14:10:57 +0900 Subject: [PATCH 6/8] refactor: Remove User model from Prisma schema to streamline database structure and improve maintainability --- prisma/schema.prisma | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 00e4bc6..46bd335 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -7,18 +7,6 @@ datasource db { url = env("DATABASE_URL") } -model User { - id Int @id @default(autoincrement()) - username String @unique - phone String? - email String? - password String? - kakao_id String? - avatar String? - created_at DateTime @default(now()) - updated_at DateTime @updatedAt -} - model MS_SUITABLE { id Int @id @default(autoincrement()) product_name String @db.VarChar(200) From a964e31dee27b23ccacaa015122384786d77241e Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 14:12:16 +0900 Subject: [PATCH 7/8] fix: Enable login redirection in middleware to ensure authenticated access to protected routes --- src/middleware.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 1bcfd96..115fd8a 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -10,9 +10,9 @@ export async function middleware(request: NextRequest) { const session = await getIronSession(cookieStore, sessionOptions) // todo: 로그인 기능 추가 시 주석 해제 - // if (!session.isLoggedIn) { - // return NextResponse.redirect(new URL('/login', request.url)) - // } + if (!session.isLoggedIn) { + return NextResponse.redirect(new URL('/login', request.url)) + } return NextResponse.next() } From 0cd95c6affa166c455dd069ee4abac0715560ca3 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 21 May 2025 14:14:37 +0900 Subject: [PATCH 8/8] refactor: Make UPT_DT field optional in MS_SUITABLE_ROOF_MATERIAL_GROUP model for improved data flexibility --- prisma/schema.prisma | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 46bd335..17cc1f4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -169,11 +169,11 @@ model BC_COMM_L { } model MS_SUITABLE_ROOF_MATERIAL_GROUP { - ID Int @id @default(autoincrement()) - ROOF_MATERIAL_GROUP String @db.VarChar(200) - ROOF_MT_CD String @db.VarChar(200) - REG_DT DateTime @default(now(), map: "DF__MS_SUITAB__creat__4F7CD00D") - UPT_DT DateTime + ID Int @id @default(autoincrement()) + ROOF_MATERIAL_GROUP String @db.VarChar(200) + ROOF_MT_CD String @db.VarChar(200) + REG_DT DateTime @default(now(), map: "DF__MS_SUITAB__creat__4F7CD00D") + UPT_DT DateTime? } model MS_SUITABLE_DETAIL {