diff --git a/FE/src/components/Header.tsx b/FE/src/components/Header.tsx
index 54b70cb8..97657c29 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 (
diff --git a/FE/src/components/Login/index.tsx b/FE/src/components/Login/index.tsx
index c8be634f..13946c43 100644
--- a/FE/src/components/Login/index.tsx
+++ b/FE/src/components/Login/index.tsx
@@ -1,13 +1,20 @@
import useLoginModalStore from 'store/useLoginModalStore';
import Input from './Input';
import { ChatBubbleOvalLeftIcon } from '@heroicons/react/16/solid';
-import { FormEvent, useState } from 'react';
+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;
@@ -19,7 +26,8 @@ export default function Login() {
return;
}
- console.log(res);
+ setAccessToken(res.accessToken);
+ toggleModal();
};
return (
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;