From 75d20ca3ea2a0933fe32575d925a16d5f4ad09cb Mon Sep 17 00:00:00 2001 From: KimCookieYa Date: Tue, 7 May 2024 01:46:49 +0900 Subject: [PATCH 1/2] wip --- BE/verifier/error-logs/2024-05-06.log | 0 BE/verifier/logs/2024-05-06.log | 9 +++ .../src/api/{Auth.ts => User.ts} | 6 ++ FE/service-homepage/src/app/(home)/layout.tsx | 4 +- .../src/app/(home)/my-page/page.tsx | 65 +++++++++++++++++-- .../src/app/(home)/notification/page.tsx | 2 +- FE/service-homepage/src/app/(sign)/layout.tsx | 23 +++++++ .../src/app/(sign)/login/page.tsx | 3 +- FE/service-homepage/src/app/(sign)/page.tsx | 30 ++------- .../src/app/(sign)/register/page.tsx | 2 +- .../src/app/_component/NavFooter.tsx | 2 +- .../src/app/_component/header.tsx | 2 +- .../src/app/api/user/verify-proof/route.ts | 18 +++++ FE/service-homepage/src/app/layout.tsx | 6 +- FE/service-homepage/src/lib/session.ts | 1 + 15 files changed, 133 insertions(+), 40 deletions(-) create mode 100644 BE/verifier/error-logs/2024-05-06.log create mode 100644 BE/verifier/logs/2024-05-06.log rename FE/service-homepage/src/api/{Auth.ts => User.ts} (83%) create mode 100644 FE/service-homepage/src/app/api/user/verify-proof/route.ts diff --git a/BE/verifier/error-logs/2024-05-06.log b/BE/verifier/error-logs/2024-05-06.log new file mode 100644 index 0000000..e69de29 diff --git a/BE/verifier/logs/2024-05-06.log b/BE/verifier/logs/2024-05-06.log new file mode 100644 index 0000000..a16aa60 --- /dev/null +++ b/BE/verifier/logs/2024-05-06.log @@ -0,0 +1,9 @@ +[VERIFIER] Info 5/6/2024, 8:05:01 AM [RoutesResolver] VerifierAPIController {/api/verifier}: +[VERIFIER] Info 5/6/2024, 8:05:01 AM [RouterExplorer] Mapped {/api/verifier/verify-proof, POST} route +[VERIFIER] Info 5/6/2024, 8:05:01 AM [NestApplication] Nest application successfully started +[VERIFIER] Info 5/6/2024, 8:05:03 AM [RoutesResolver] VerifierAPIController {/api/verifier}: +[VERIFIER] Info 5/6/2024, 8:05:03 AM [RouterExplorer] Mapped {/api/verifier/verify-proof, POST} route +[VERIFIER] Info 5/6/2024, 8:05:03 AM [NestApplication] Nest application successfully started +[VERIFIER] Info 5/6/2024, 10:53:49 AM [RoutesResolver] VerifierAPIController {/api/verifier}: +[VERIFIER] Info 5/6/2024, 10:53:49 AM [RouterExplorer] Mapped {/api/verifier/verify-proof, POST} route +[VERIFIER] Info 5/6/2024, 10:53:49 AM [NestApplication] Nest application successfully started diff --git a/FE/service-homepage/src/api/Auth.ts b/FE/service-homepage/src/api/User.ts similarity index 83% rename from FE/service-homepage/src/api/Auth.ts rename to FE/service-homepage/src/api/User.ts index b6a6433..052e6db 100644 --- a/FE/service-homepage/src/api/Auth.ts +++ b/FE/service-homepage/src/api/User.ts @@ -30,3 +30,9 @@ export async function getUserInfo() { export async function getCheckLogin() { return clientAxios.get('/api/user/me'); } + +export async function postVerifyProof(proof: string) { + return clientAxios.post('/api/user/verify-proof', { + proof, + }); +} diff --git a/FE/service-homepage/src/app/(home)/layout.tsx b/FE/service-homepage/src/app/(home)/layout.tsx index 3d10584..e9c8dbb 100644 --- a/FE/service-homepage/src/app/(home)/layout.tsx +++ b/FE/service-homepage/src/app/(home)/layout.tsx @@ -6,7 +6,7 @@ import { useToast } from '@/stores/useToastStore'; import { useRouter } from 'next/navigation'; import Toast from '@/app/_component/Toast'; import { useEffect } from 'react'; -import { getCheckLogin, getUserInfo } from '@/api/Auth'; +import { getCheckLogin, getUserInfo } from '@/api/User'; import { IUserInfo } from '@/types/auth'; export default function HomeLayout({ @@ -31,7 +31,7 @@ export default function HomeLayout({ const fetchCheckLogin = async () => { const res = await getCheckLogin(); - if (res.status <= 300) { + if (res.data.result <= 300) { console.log(res.data.data); const res2 = await fetchMe(); console.log(res2); diff --git a/FE/service-homepage/src/app/(home)/my-page/page.tsx b/FE/service-homepage/src/app/(home)/my-page/page.tsx index 9493d4f..160594f 100644 --- a/FE/service-homepage/src/app/(home)/my-page/page.tsx +++ b/FE/service-homepage/src/app/(home)/my-page/page.tsx @@ -1,11 +1,19 @@ 'use client'; import useWalletStore from '@/stores/useWalletStore'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { FaHeart } from 'react-icons/fa'; +import useUserInfoStore from '@/stores/useUserInfoStore'; +import { useRouter } from 'next/navigation'; +import { postLogout } from '@/api/User'; +import { useToast } from '@/stores/useToastStore'; export default function MyPagePage() { + const router = useRouter(); const { isInstalled, setInstalled } = useWalletStore(); + const toastStore = useToast(); + const { userInfo, logout } = useUserInfoStore((state) => state); + const [proof, setProof] = useState(''); useEffect(() => { setTimeout(() => { @@ -20,25 +28,66 @@ export default function MyPagePage() { useEffect(() => { if (isInstalled) { - console.log('installed'); + console.log('wallet is installed'); + } else { + console.log("wallet isn't installed"); } }, [isInstalled]); const onConnectWallet = () => { alert('지갑 연결!'); + sendMessageToExtension(); }; const onInstallWallet = () => { alert('크롬 웹스토어로 이동합니다!'); }; + useEffect(() => { + // 확장 앱으로부터 메시지를 받기 위한 이벤트 리스너 + window.addEventListener('message', (event) => { + if (event.origin !== window.location.origin) return; + + if (event.data.type === 'FROM_EXTENSION_TO_PAGE') { + console.log(JSON.parse(event.data.message)); + alert(`Message from extension: ${event.data.message}`); + setProof(event.data.message); + } + }); + }, []); + + // 버튼 클릭시 메시지 보내기 + const sendMessageToExtension = () => { + window.postMessage( + { type: 'FROM_PAGE', text: 'Hello, extension!' }, + '*' + ); + }; + + const onLogout = async () => { + logout(); + await postLogout(); + toastStore.openToast('로그아웃 되었습니다.', 'success', () => { + router.push('/'); + }); + }; + return (

마이페이지

- + - + +
proof: {proof}
{/* {isInstalled ? (*/} {/*
+
+ +
); } diff --git a/FE/service-homepage/src/app/(home)/notification/page.tsx b/FE/service-homepage/src/app/(home)/notification/page.tsx index b73e5a0..bac2876 100644 --- a/FE/service-homepage/src/app/(home)/notification/page.tsx +++ b/FE/service-homepage/src/app/(home)/notification/page.tsx @@ -35,7 +35,7 @@ export default function NotificationPage() {

{userInfo?.nickname}의 내역

{alarmList.length > 0 ? ( -
+
{alarmList.map((alarm, index) => ( ))} diff --git a/FE/service-homepage/src/app/(sign)/layout.tsx b/FE/service-homepage/src/app/(sign)/layout.tsx index 4b3a590..6f0151e 100644 --- a/FE/service-homepage/src/app/(sign)/layout.tsx +++ b/FE/service-homepage/src/app/(sign)/layout.tsx @@ -1,7 +1,30 @@ +'use client'; + +import useUserInfoStore from '@/stores/useUserInfoStore'; +import { useRouter } from 'next/navigation'; +import { useEffect } from 'react'; +import { useToast } from '@/stores/useToastStore'; + export default function LandingLayout({ children, }: { children: React.ReactNode; }) { + const userInfo = useUserInfoStore((state) => state.userInfo); + const openToast = useToast((state) => state.openToast); + const router = useRouter(); + + useEffect( + function checkLoginEffect() { + console.log('userInfo: ', userInfo); + if (userInfo) { + openToast('로그인됨', 'error', () => { + router.push('/pond'); + }); + } + }, + [userInfo] + ); + return <>{children}; } diff --git a/FE/service-homepage/src/app/(sign)/login/page.tsx b/FE/service-homepage/src/app/(sign)/login/page.tsx index 169d6a5..948cde1 100644 --- a/FE/service-homepage/src/app/(sign)/login/page.tsx +++ b/FE/service-homepage/src/app/(sign)/login/page.tsx @@ -2,7 +2,7 @@ import { SubmitHandler, useForm } from 'react-hook-form'; import { IUserInfo, IUserInfoForm } from '@/types/auth'; -import { getUserInfo, postLogin } from '@/api/Auth'; +import { getUserInfo, postLogin } from '@/api/User'; import useUserInfoStore from '@/stores/useUserInfoStore'; import { useRouter } from 'next/navigation'; import UserInfoInput from '@/app/(sign)/_component/UserInfoInput'; @@ -32,7 +32,6 @@ export default function Page() { const onSubmit: SubmitHandler = async (data) => { const res = await postLogin(data.id, data.password); if (res.data.result <= 300) { - openToast('로그인 성공', 'success', () => router.push('/pond')); console.log(res.data); const userInfo = await fetchMe(); console.log(userInfo); diff --git a/FE/service-homepage/src/app/(sign)/page.tsx b/FE/service-homepage/src/app/(sign)/page.tsx index b2b6f46..5bbb817 100644 --- a/FE/service-homepage/src/app/(sign)/page.tsx +++ b/FE/service-homepage/src/app/(sign)/page.tsx @@ -1,28 +1,6 @@ -'use client'; - -import { useEffect } from 'react'; import Link from 'next/link'; export default function Home() { - useEffect(() => { - // 확장 앱으로부터 메시지를 받기 위한 이벤트 리스너 - window.addEventListener('message', (event) => { - if (event.origin !== window.location.origin) return; - - if (event.data.type === 'FROM_EXTENSION_TO_PAGE') { - alert(`Message from extension: ${event.data.message}`); - } - }); - }, []); - - // 버튼 클릭시 메시지 보내기 - const sendMessageToExtension = () => { - window.postMessage( - { type: 'FROM_PAGE', text: 'Hello, extension!' }, - '*' - ); - }; - return (