diff --git a/.env.development b/.env.development index 53e90fd..c8a3ab5 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1,7 @@ # 모바일 디바이스로 로컬 서버 확인하려면 자신 IP 주소로 변경 # 다시 로컬에서 개발할때는 localhost로 변경 -NEXT_PUBLIC_API_URL=http://localhost:3000 \ No newline at end of file +#route handler +NEXT_PUBLIC_API_URL=http://localhost:3000 + +#qsp 로그인 api +NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 \ No newline at end of file diff --git a/.env.production b/.env.production index f5f1630..1d169db 100644 --- a/.env.production +++ b/.env.production @@ -1 +1,5 @@ -NEXT_PUBLIC_API_URL=http://172.30.1.35:3000 \ No newline at end of file +#route handler +NEXT_PUBLIC_API_URL=http://172.30.1.35:3000 + +#qsp 로그인 api +NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index 1ff5ba6..bc718b5 100644 --- a/next.config.ts +++ b/next.config.ts @@ -9,9 +9,13 @@ const nextConfig: NextConfig = { async rewrites() { return [ { - source: '/api/:path*', - destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`, + source: '/api/user/login', + destination: `${process.env.NEXT_PUBLIC_QSP_API_URL}/api/user/login`, }, + // { + // source: '/api/:path*', + // destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`, + // }, ] }, } diff --git a/src/app/api/auth/route.ts b/src/app/api/auth/route.ts new file mode 100644 index 0000000..f9fc859 --- /dev/null +++ b/src/app/api/auth/route.ts @@ -0,0 +1,14 @@ +import { axiosInstance } from '@/libs/axios' +import { NextResponse } from 'next/server' + +export async function POST(request: Request) { + const { loginId, pwd } = await request.json() + + const result = await axiosInstance(`${process.env.NEXT_PUBLIC_QSP_API_URL}`).post(`/api/user/login`, { + loginId, + pwd, + }) + console.log('🚀 ~ result ~ result:', result) + + return NextResponse.json('ok') +} diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 8f6e373..c17373f 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -1,16 +1,68 @@ 'use client' -import { useState } from 'react' +import { axiosInstance } from '@/libs/axios' +import { useQuery } from '@tanstack/react-query' +import { useEffect, useReducer, useState } from 'react' +import { AxiosResponse } from 'axios' + +interface AccountState { + loginId: string + pwd: string +} export default function Login() { - const [pwShow, setPwShow] = useState(false) //비밀번호 보이기 숨기기 + //비밀번호 보이기 숨기기 + const [pwShow, setPwShow] = useState(false) + //ID 저장 체크박스 + const [idSave, setIdSave] = useState(false) + //Q.PARTNERS 체크박스 + const [isPartners, setIsPartners] = useState(false) + //로그인 상태 + const [isLogin, setIsLogin] = useState(false) + + const reducer = (state: AccountState, newState: Partial) => ({ ...state, ...newState }) + const [account, setAccount] = useReducer(reducer, { + loginId: '', + pwd: '', + }) + + const { + data: loginData, + isPending, + error, + } = useQuery({ + queryKey: ['login', 'account'], + queryFn: () => { + const result = axiosInstance('').post(`/api/auth`, { + loginId: account.loginId, + pwd: account.pwd, + }) + return result + }, + enabled: isLogin, + staleTime: 0, + retry: false, + }) + + useEffect(() => { + if (loginData) { + console.log('🚀 ~ Login ~ loginData:', loginData) + setIsLogin(false) + } + }, [loginData]) return ( <>
- + setAccount({ loginId: e.target.value })} + /> @@ -18,7 +70,13 @@ export default function Login() {
- + setAccount({ pwd: e.target.value })} + /> @@ -26,19 +84,19 @@ export default function Login() {
- + setIdSave(!idSave)} />
Q.PARTNERS
-
diff --git a/src/libs/axios.ts b/src/libs/axios.ts index 9f3aa8d..db7a625 100644 --- a/src/libs/axios.ts +++ b/src/libs/axios.ts @@ -1,16 +1,17 @@ import axios from 'axios' -const baseURL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000' - -export const axiosInstance = axios.create({ - baseURL, - headers: { - 'Content-Type': 'application/json', - }, -}) +export const axiosInstance = (url: string) => { + let baseURL = url !== '' || url === undefined ? url : process.env.NEXT_PUBLIC_API_URL + return axios.create({ + baseURL, + headers: { + Accept: 'application/json', + }, + }) +} // Request interceptor -axiosInstance.interceptors.request.use( +axios.interceptors.request.use( (config) => { // 여기에 토큰 추가 등의 공통 로직을 넣을 수 있습니다 return config