diff --git a/FE/src/components/Header.tsx b/FE/src/components/Header.tsx index 54b70cb8..b2b294fb 100644 --- a/FE/src/components/Header.tsx +++ b/FE/src/components/Header.tsx @@ -1,7 +1,9 @@ +import useAuthStore from 'store/authStore'; import useLoginModalStore from 'store/useLoginModalStore'; export default function Header() { const { toggleModal } = useLoginModalStore(); + const { isLogin, resetToken } = useAuthStore(); return (
@@ -26,15 +28,26 @@ export default function Header() {
- - + {isLogin ? ( + + ) : ( + <> + + {/* */} + + )}
diff --git a/FE/src/components/Login/Input.tsx b/FE/src/components/Login/Input.tsx index cb910d07..b6b78ab1 100644 --- a/FE/src/components/Login/Input.tsx +++ b/FE/src/components/Login/Input.tsx @@ -1,16 +1,12 @@ -import { HTMLInputTypeAttribute } from 'react'; +import { ComponentProps } from 'react'; -type LoginInputProps = { - type: HTMLInputTypeAttribute; - placeholder: string; -}; +type LoginInputProps = ComponentProps<'input'>; -export default function Input({ type, placeholder }: LoginInputProps) { +export default function Input({ ...props }: LoginInputProps) { return ( ); } diff --git a/FE/src/components/Login/index.tsx b/FE/src/components/Login/index.tsx index ce03ff78..fbe4e418 100644 --- a/FE/src/components/Login/index.tsx +++ b/FE/src/components/Login/index.tsx @@ -1,30 +1,65 @@ import useLoginModalStore from 'store/useLoginModalStore'; import Input from './Input'; import { ChatBubbleOvalLeftIcon } from '@heroicons/react/16/solid'; +import { FormEvent, useEffect, useState } from 'react'; +import { login } from 'service/auth'; +import useAuthStore from 'store/authStore'; export default function Login() { const { isOpen, toggleModal } = useLoginModalStore(); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const { setAccessToken } = useAuthStore(); + + useEffect(() => { + setEmail(''); + setPassword(''); + }, [isOpen]); if (!isOpen) return; + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + const res = await login(email, password); + + if ('error' in res) { + return; + } + + setAccessToken(res.accessToken); + toggleModal(); + }; + return ( <> toggleModal()} />

JuGa

-
- - -
-
+
+
+ setEmail(e.target.value)} + autoComplete='username' + /> + setPassword(e.target.value)} + autoComplete='current-password' + /> +
- -
+ +
); @@ -32,6 +67,6 @@ export default function Login() { function Overay({ onClick }: { onClick: () => void }) { return ( -
+
); } diff --git a/FE/src/components/StockIndex/Chart.tsx b/FE/src/components/StockIndex/Chart.tsx index b3e17c8e..2ab43205 100644 --- a/FE/src/components/StockIndex/Chart.tsx +++ b/FE/src/components/StockIndex/Chart.tsx @@ -39,7 +39,6 @@ export function Chart({ name }: StockIndexChartProps) {

-31.55(-1.2%)

{ + return fetch('http://223.130.151.42:3000/auth/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + email, + password, + }), + }).then((res) => res.json()); +} diff --git a/FE/src/store/authStore.ts b/FE/src/store/authStore.ts new file mode 100644 index 00000000..1a8e8453 --- /dev/null +++ b/FE/src/store/authStore.ts @@ -0,0 +1,21 @@ +import { create } from 'zustand'; + +type AuthStore = { + accessToken: string | null; + isLogin: boolean; + setAccessToken: (token: string) => void; + resetToken: () => void; +}; + +const useAuthStore = create((set) => ({ + accessToken: null, + isLogin: false, + setAccessToken: (token: string) => { + set({ accessToken: token, isLogin: token !== null }); + }, + resetToken: () => { + set({ accessToken: null, isLogin: false }); + }, +})); + +export default useAuthStore; diff --git a/FE/src/types.ts b/FE/src/types.ts new file mode 100644 index 00000000..06b1b10b --- /dev/null +++ b/FE/src/types.ts @@ -0,0 +1,9 @@ +export type LoginSuccessResponse = { + accessToken: string; +}; + +export type LoginFailResponse = { + error: string; + message: string[]; + statusCode: number; +}; diff --git a/FE/src/utils/chart.ts b/FE/src/utils/chart.ts index c03f418a..15b515f9 100644 --- a/FE/src/utils/chart.ts +++ b/FE/src/utils/chart.ts @@ -31,8 +31,6 @@ export const drawChart = (ctx: CanvasRenderingContext2D, data: number[]) => { chartHeight - (chartHeight * (point - yMin)) / (yMax - yMin); - console.log(point); - if (i === 0) { ctx.moveTo(x, y); } else {