From 1d1a917561d51eb55534391888de1fc6be21b757 Mon Sep 17 00:00:00 2001 From: eunhak Date: Mon, 3 Jun 2024 15:30:54 +0900 Subject: [PATCH] test: fcm test --- src/api/fcm/fcm.post.api.ts | 12 ++++++++++++ src/components/pwa/Fcm.tsx | 2 +- src/hook/useLogin.ts | 8 ++++++-- src/pages/sign/index.tsx | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/api/fcm/fcm.post.api.ts diff --git a/src/api/fcm/fcm.post.api.ts b/src/api/fcm/fcm.post.api.ts new file mode 100644 index 0000000..0c3300f --- /dev/null +++ b/src/api/fcm/fcm.post.api.ts @@ -0,0 +1,12 @@ +import { postRequest } from '../request'; +import { ICommon } from '../types/common'; + +export const fcmpost = async ({ fcmToken }: { fcmToken: string | void | undefined }) => { + const response = postRequest, { fcmToken: string | void | undefined }>( + 'fcm-token', + { + fcmToken + } + ); + return response; +}; diff --git a/src/components/pwa/Fcm.tsx b/src/components/pwa/Fcm.tsx index c1bef43..36db686 100644 --- a/src/components/pwa/Fcm.tsx +++ b/src/components/pwa/Fcm.tsx @@ -57,7 +57,7 @@ export const getTokenHandler = async () => { console.error('토큰 생성 불가'); } else { // 토큰을 받았다면 여기서 supabase 테이블의 저장하면 됩니다. - console.log('currentToken', currentToken); + // console.log('currentToken', currentToken); return currentToken; } }) diff --git a/src/hook/useLogin.ts b/src/hook/useLogin.ts index 53c50c2..bc2561c 100644 --- a/src/hook/useLogin.ts +++ b/src/hook/useLogin.ts @@ -4,14 +4,18 @@ import { setCookie } from '@/utils/cookies'; import { useRouter } from 'next/navigation'; import { useMutation } from '@tanstack/react-query'; import { useState } from 'react'; +import { getTokenHandler } from '@/components/pwa/Fcm'; +import { fcmpost } from '@/api/fcm/fcm.post.api'; const useLogin = () => { const router = useRouter(); const [error, setError] = useState(''); - const onSuccess = (data: UserLoginType) => { + + const onSuccess = async (data: UserLoginType) => { const { accessToken } = data.data; const cookieOptions = { path: '/', maxAge: 600000 * 15 }; - + const token = await getTokenHandler(); + fcmpost({ fcmToken: token }); setCookie('token', accessToken, cookieOptions); router.push('/'); diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 38889b7..f3c4e3d 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -38,7 +38,7 @@ const SignHomePage = () => { fetchToken(); }, []); - // console.log(FcmToken); + console.log(FcmToken); return (