diff --git a/src/app/api/auth/chg-pwd/route.ts b/src/app/api/auth/chg-pwd/route.ts index 321a69f..c218a04 100644 --- a/src/app/api/auth/chg-pwd/route.ts +++ b/src/app/api/auth/chg-pwd/route.ts @@ -1,24 +1,28 @@ import { NextResponse } from 'next/server' +import { HttpStatusCode } from 'axios' import { loggerWrapper } from '@/libs/api-wrapper' import { axiosInstance } from '@/libs/axios' async function setChgPwd(req: Request): Promise { const { loginId, email, pwd, chgPwd } = await req.json() - console.log('๐Ÿš€ ~ POST ~ loginId:', loginId) - console.log('๐Ÿš€ ~ POST ~ email:', email) - console.log('๐Ÿš€ ~ POST ~ pwd:', pwd) - console.log('๐Ÿš€ ~ POST ~ chgPwd:', chgPwd) - const result = await axiosInstance(`${process.env.NEXT_PUBLIC_QSP_API_URL}`).post(`/api/user/userPwdChg`, { + const res = await axiosInstance(`${process.env.NEXT_PUBLIC_QSP_API_URL}`).post(`/api/user/userPwdChg`, { loginId, chgType: 'C', email, pwd, chgPwd, }) - console.log('๐Ÿš€ ~ result ~ result:', result) - return NextResponse.json({ code: 200, data: result.data }) + console.log('๐Ÿš€ ~ qsp userPwdChg api response ~ response.data:', res.data) + + if (res.data.result.resultCode !== 'S') { + const errorMsg = res.data.result.resultMsg + console.error(`๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: ${errorMsg}`) + return NextResponse.json({ error: `๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: ${errorMsg}` }, { status: HttpStatusCode.InternalServerError }) + } + + return NextResponse.json(res.data) } export const POST = loggerWrapper(setChgPwd) diff --git a/src/app/pw-reset/layout.tsx b/src/app/pw-reset/layout.tsx index eb72abf..e7802bb 100644 --- a/src/app/pw-reset/layout.tsx +++ b/src/app/pw-reset/layout.tsx @@ -11,8 +11,8 @@ export default function layout({ children }: PwResetLayoutProps) {
-
ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใ‚’ใƒชใ‚ปใƒƒใƒˆใ™ใ‚‹
-
ๆ–ฐใ—ใ„ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„.
+
ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใƒชใ‚ปใƒƒใƒˆ
+
ๆ–ฐใ—ใ„ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„ใ€‚
{children} diff --git a/src/components/pw-reset/PwResetForm.tsx b/src/components/pw-reset/PwResetForm.tsx index ac2d99f..67d622e 100644 --- a/src/components/pw-reset/PwResetForm.tsx +++ b/src/components/pw-reset/PwResetForm.tsx @@ -1,7 +1,8 @@ 'use client' -import { useState } from 'react' +import { useEffect, useState } from 'react' import { useRouter } from 'next/navigation' +import { HttpStatusCode } from 'axios' import { useLocalStorage } from 'usehooks-ts' @@ -21,33 +22,45 @@ export default function PwResetForm() { const [value, setValue, removeValue] = useLocalStorage<{ indivisualData: string }>('hanasysIndivisualState', { indivisualData: '' }) const validatePwd = () => { - // ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ธธ์ด ์ฒดํฌ (8๊ธ€์ž ์ด์ƒ) + /* ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ ์ฒดํฌ */ + if (pwd01 === '') { + alert('ๆ–ฐใ—ใ„ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใฎๅ…ฅๅŠ›ใ‚’ใŠ้ก˜ใ„ใ—ใพใ™ใ€‚') + return false + } + + /* ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์ž…๋ ฅ ์ฒดํฌ */ + if (pwd02 === '') { + alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใ‚’ใ‚‚ใ†ไธ€ๅบฆๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„ใ€‚') + return false + } + + /* ๋‘ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ผ์น˜ ์ฒดํฌ */ + if (pwd01 !== pwd02) { + alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใŒไธ€่‡ดใ—ใพใ›ใ‚“ใ€‚') + return false + } + + /* ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ธธ์ด ์ฒดํฌ (8๊ธ€์ž ์ด์ƒ) */ if (pwd01.length < 8) { alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใฏ8ๆ–‡ๅญ—ไปฅไธŠใงใชใ‘ใ‚Œใฐใชใ‚Šใพใ›ใ‚“ใ€‚') return false } - // ์˜๋ฌธ ๋Œ€๋ฌธ์ž ํฌํ•จ ์ฒดํฌ + /* ์˜๋ฌธ ๋Œ€๋ฌธ์ž ํฌํ•จ ์ฒดํฌ */ if (!/[A-Z]/.test(pwd01)) { alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใซ่‹ฑๅคงๆ–‡ๅญ—ใ‚’ๅซใ‚ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚Šใพใ™ใ€‚') return false } - // ์˜๋ฌธ ์†Œ๋ฌธ์ž ํฌํ•จ ์ฒดํฌ + /* ์˜๋ฌธ ์†Œ๋ฌธ์ž ํฌํ•จ ์ฒดํฌ */ if (!/[a-z]/.test(pwd01)) { alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใซ่‹ฑ่ชžใฎๅฐๆ–‡ๅญ—ใ‚’ๅซใ‚ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚Šใพใ™ใ€‚') return false } - // ์ˆซ์ž ํฌํ•จ ์ฒดํฌ + /* ์ˆซ์ž ํฌํ•จ ์ฒดํฌ */ if (!/[0-9]/.test(pwd01)) { - alert('๋น„ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใซๆ•ฐๅญ—ใ‚’ๅซใ‚ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚Šใพใ™ใ€‚') - return false - } - - // ๋‘ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ผ์น˜ ์ฒดํฌ - if (pwd01 !== pwd02) { - alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใŒไธ€่‡ดใ—ใพใ›ใ‚“ใ€‚') + alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใซๆ•ฐๅญ—ใ‚’ๅซใ‚ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚Šใพใ™ใ€‚') return false } @@ -56,30 +69,39 @@ export default function PwResetForm() { const handleReset = async () => { if (validatePwd()) { - const { data } = await axiosInstance(null).post(`/api/auth/chg-pwd`, { + const req: Record = { loginId: session.userId, email: session.email, pwd: value.indivisualData, chgPwd: pwd01, - }) - - if (data.data.result.resultCode === 'S') { - setValue({ indivisualData: pwd01 }) } - window.neoAlert(data.data.result.resultMsg, () => { + const res = await axiosInstance(null).post(`/api/auth/chg-pwd`, req) + + if (res.status !== HttpStatusCode.Ok) { + console.error(`ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใฎๅค‰ๆ›ดใซๅคฑๆ•—ใ—ใพใ—ใŸใ€‚: ${res.data.error}`) + alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใฎๅค‰ๆ›ดใซๅคฑๆ•—ใ—ใพใ—ใŸใ€‚') + return + } else { + setValue({ indivisualData: pwd01 }) + alert('ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใŒๅค‰ๆ›ดใ•ใ‚Œใพใ—ใŸใ€‚') router.back() - }) + } } } + /* ํŒŒํŠธ๋„ˆ ๊ฐ•์ œ ์ง„์ž… ๋ฐฉ์–ด */ + useEffect(() => { + if (session.isLoggedIn && session.role === 'Partner') router.back() + }, [session.role, session.isLoggedIn, router]) + return ( <>
- ๆ–ฐ่ฆใƒ‘ใ‚นใƒฏใƒผใƒ‰ๅ†ๅ…ฅๅŠ› * + ๆ–ฐใ—ใ„ใƒ‘ใ‚นใƒฏใƒผใƒ‰ๅ…ฅๅŠ› *
@@ -94,11 +116,11 @@ export default function PwResetForm() {
-
10ๆ–‡ๅญ—ไปฅๅ†…
+ {/*
โ€ปๅŠ่ง’10ๆ–‡ๅญ—ไปฅๅ†…
*/}
- ๆ–ฐ่ฆใƒ‘ใ‚นใƒฏใƒผใƒ‰ๅ…ฅๅŠ› * + ๆ–ฐใ—ใ„ใƒ‘ใ‚นใƒฏใƒผใƒ‰ใ‚’ๅ†ๅ…ฅๅŠ› *
@@ -113,18 +135,18 @@ export default function PwResetForm() {
-
10ๆ–‡ๅญ—ไปฅๅ†…
+ {/*
โ€ปๅŠ่ง’10ๆ–‡ๅญ—ไปฅๅ†…
*/}