diff --git a/weatherfit_refactoring/package-lock.json b/weatherfit_refactoring/package-lock.json index 30ab142..35fd8b7 100644 --- a/weatherfit_refactoring/package-lock.json +++ b/weatherfit_refactoring/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "dependencies": { "axios": "^1.6.7", + "js-cookie": "^3.0.5", "next": "14.0.4", "react": "^18", "react-dom": "^18", @@ -18,6 +19,7 @@ "zustand": "^4.4.7" }, "devDependencies": { + "@types/js-cookie": "^3.0.6", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", @@ -453,6 +455,12 @@ "tslib": "^2.4.0" } }, + "node_modules/@types/js-cookie": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-3.0.6.tgz", + "integrity": "sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==", + "dev": true + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -2850,6 +2858,14 @@ "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==", "peer": true }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "engines": { + "node": ">=14" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/weatherfit_refactoring/package.json b/weatherfit_refactoring/package.json index a61eb6a..74dddee 100644 --- a/weatherfit_refactoring/package.json +++ b/weatherfit_refactoring/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "axios": "^1.6.7", + "js-cookie": "^3.0.5", "next": "14.0.4", "react": "^18", "react-dom": "^18", @@ -20,6 +21,7 @@ "zustand": "^4.4.7" }, "devDependencies": { + "@types/js-cookie": "^3.0.6", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", diff --git a/weatherfit_refactoring/src/Components/Molecules/LoginForm.tsx b/weatherfit_refactoring/src/Components/Molecules/LoginForm.tsx index c56244f..c0bd053 100644 --- a/weatherfit_refactoring/src/Components/Molecules/LoginForm.tsx +++ b/weatherfit_refactoring/src/Components/Molecules/LoginForm.tsx @@ -4,15 +4,13 @@ import InputStore, { InputStyle } from '@/Components/Atoms/Input/InputStore' import { confirmAlert } from '@/utils/function/utilFunction' import { useRouter } from 'next/navigation' import { FormEvent, useState } from 'react' -import { useAuth } from '../../../contexts/AuthContext' -import AuthUserEmailStore from '@/Store/AuthUserEmail' +import { AuthUserStore } from '@/Store/AuthUser' export default function LoginForm() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') - const { userEmail, setUserEmail } = AuthUserEmailStore() + const { setUserEmail } = AuthUserStore() const router = useRouter() - const { login } = useAuth() const handleLogin = async (e: FormEvent) => { e.preventDefault() @@ -36,10 +34,9 @@ export default function LoginForm() { const loginRes = await res.json() console.log('로그인 loginRes: ', loginRes) + document.cookie = `accessToken=${loginRes.token}; path=/` setUserEmail(loginRes.email) - // login(loginRes.email, loginRes.token) - confirmAlert(`${loginRes.nickname}님 환영합니다!`) router.push('/') diff --git a/weatherfit_refactoring/src/Components/Molecules/NavBarBox.tsx b/weatherfit_refactoring/src/Components/Molecules/NavBarBox.tsx index 222d779..0027273 100644 --- a/weatherfit_refactoring/src/Components/Molecules/NavBarBox.tsx +++ b/weatherfit_refactoring/src/Components/Molecules/NavBarBox.tsx @@ -17,10 +17,8 @@ export default function NavBarBox({ iconStyle, title, url }: Props) { const [isActive, setIsActive] = useState(false) useEffect(() => { - console.log('pathname: ', pathname) setIsActive(pathname === url) }, [pathname]) - console.log('isActive: ', isActive) const activeIconStyle = isActive ? IconStyle[`${iconStyle}_FILL` as keyof typeof IconStyle] diff --git a/weatherfit_refactoring/src/Store/AuthToken.ts b/weatherfit_refactoring/src/Store/AuthToken.ts new file mode 100644 index 0000000..7d2a649 --- /dev/null +++ b/weatherfit_refactoring/src/Store/AuthToken.ts @@ -0,0 +1,12 @@ +import { create } from 'zustand' +import Cookies from 'js-cookie' + +interface AuthToken { + accesstoken: string | undefined + setAccessToken: () => void +} + +export const AuthTokenStore = create(set => ({ + accesstoken: undefined, + setAccessToken: () => set({ accesstoken: Cookies.get('accessToken') }), +})) diff --git a/weatherfit_refactoring/src/Store/AuthUser.ts b/weatherfit_refactoring/src/Store/AuthUser.ts new file mode 100644 index 0000000..a68180d --- /dev/null +++ b/weatherfit_refactoring/src/Store/AuthUser.ts @@ -0,0 +1,21 @@ +import { create } from 'zustand' +import { persist } from 'zustand/middleware' + +interface AuthUser { + userEmail: string | null + setUserEmail: (userEmail: string | null) => void +} + +export const AuthUserStore = create( + persist( + set => ({ + userEmail: null, + setUserEmail: userEmail => { + set({ userEmail }) + }, + }), + { + name: 'user_email', // 로컬 스토리지 저장 이름 + }, + ), +) diff --git a/weatherfit_refactoring/src/Store/AuthUserEmail.ts b/weatherfit_refactoring/src/Store/AuthUserEmail.ts deleted file mode 100644 index ff591bc..0000000 --- a/weatherfit_refactoring/src/Store/AuthUserEmail.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { create } from 'zustand' -import { persist } from 'zustand/middleware' - -interface UserEmailStore { - userEmail: string | null - setUserEmail: (userEmail: string | null) => void -} - -const AuthUserEmailStore = create( - persist( - (set, get) => ({ - userEmail: null, - setUserEmail: (userEmail: string | null) => - set(() => ({ userEmail: userEmail })), - }), - { - name: 'user_email', - }, - ), -) - -export default AuthUserEmailStore diff --git a/weatherfit_refactoring/src/app/layout.tsx b/weatherfit_refactoring/src/app/layout.tsx index 64f5de2..b958355 100644 --- a/weatherfit_refactoring/src/app/layout.tsx +++ b/weatherfit_refactoring/src/app/layout.tsx @@ -1,7 +1,6 @@ import type { Metadata } from 'next' import ReactQueryProvider from '../utils/provider/ReactQueryProvider' import './globals.css' -import { AuthProvider } from '../../contexts/AuthContext' export const metadata: Metadata = { title: 'Create Next App', @@ -16,9 +15,7 @@ export default function RootLayout({ return ( - - {children} - + {children} ) diff --git a/weatherfit_refactoring/src/app/mypage/page.tsx b/weatherfit_refactoring/src/app/mypage/page.tsx index 51f83db..a2239cb 100644 --- a/weatherfit_refactoring/src/app/mypage/page.tsx +++ b/weatherfit_refactoring/src/app/mypage/page.tsx @@ -4,7 +4,6 @@ import React, { useEffect, useState } from 'react' import ProfileInfo from '@/Components/Molecules/ProfileInfo' import ProfileHeader from '@/Components/Organisms/ProfileHeader' import ProfileBoard from '@/Components/Organisms/ProfileBoard' -import AuthUserEmailStore from '@/Store/AuthUserEmail' export default function Mypage() { // 회원 정보 @@ -13,9 +12,7 @@ export default function Mypage() { const [refreshProfile, setRefreshProfile] = useState(false) // 회원 정보 변경했을 때 const [myPostData, setMyPostData] = useState([]) const [myLikePostData, setMyLikePostData] = useState([]) - const { userEmail, setUserEmail } = AuthUserEmailStore() - console.log('user email: ', userEmail) // 회원 정보 불러오기 // useEffect(() => { // const fetchData = async () => { diff --git a/weatherfit_refactoring/src/app/page.tsx b/weatherfit_refactoring/src/app/page.tsx index 0e30706..6c49f06 100644 --- a/weatherfit_refactoring/src/app/page.tsx +++ b/weatherfit_refactoring/src/app/page.tsx @@ -1,7 +1,5 @@ - import MainOrganism from '@/Components/Organisms/MainOrganism' import NavBar from '@/Components/Molecules/NavBar' -import LikeAndComment from '@/Components/Molecules/LikeAndComment' import WeatherInfo from '@/Components/Molecules/WeatherInfo' import MainHeader from '@/Components/Molecules/MainHeader' diff --git a/weatherfit_refactoring/src/utils/function/utilFunction.ts b/weatherfit_refactoring/src/utils/function/utilFunction.ts index e3e6770..1f5231e 100644 --- a/weatherfit_refactoring/src/utils/function/utilFunction.ts +++ b/weatherfit_refactoring/src/utils/function/utilFunction.ts @@ -30,6 +30,7 @@ export const handleNext = ( }) } +// sweetalert 함수 export const deleteAlert = () => { return Swal.fire({ title: '게시물 삭제',