Skip to content

Commit

Permalink
test: fcm test
Browse files Browse the repository at this point in the history
  • Loading branch information
eun-hak committed Jun 3, 2024
1 parent 0511ae2 commit 1d1a917
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/api/fcm/fcm.post.api.ts
Original file line number Diff line number Diff line change
@@ -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<ICommon<null>, { fcmToken: string | void | undefined }>(
'fcm-token',
{
fcmToken
}
);
return response;
};
2 changes: 1 addition & 1 deletion src/components/pwa/Fcm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const getTokenHandler = async () => {
console.error('토큰 생성 불가');
} else {
// 토큰을 받았다면 여기서 supabase 테이블의 저장하면 됩니다.
console.log('currentToken', currentToken);
// console.log('currentToken', currentToken);
return currentToken;
}
})
Expand Down
8 changes: 6 additions & 2 deletions src/hook/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sign/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const SignHomePage = () => {
fetchToken();
}, []);

// console.log(FcmToken);
console.log(FcmToken);
return (
<MainContainer>
<div className="flex flex-col justify-center items-center gap-[39px] h-[470px]">
Expand Down

0 comments on commit 1d1a917

Please sign in to comment.