Skip to content

Commit

Permalink
Merge pull request #240 from SCBJ-7/feature/#236-token
Browse files Browse the repository at this point in the history
[#236] fcm 토큰 발급 후 백엔드에 전달
  • Loading branch information
im-na0 authored Jan 26, 2024
2 parents e23c6e1 + 52b13c6 commit 1f61a74
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/pages/signInPage/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import * as S from "./SignIn.style";
import { useForm } from "react-hook-form";
import { Link } from "react-router-dom";
import { Link, useNavigate, useSearchParams } from "react-router-dom";
import useToastConfig from "@hooks/common/useToastConfig";
// import { PATH } from "@constants/path";
import { PATH } from "@constants/path";
import { useUserInfoStore } from "@/store/store";
import { postLogin } from "@apis/fetchLogin";
import { getMessaging, getToken } from "firebase/messaging";
import { app } from "@/firebase";
import { useState } from "react";

type FormValues = {
email: string;
password: string;
};

const SignIn = () => {
const [token, SetToken] = useState("");
// const navigate = useNavigate();
// const [searchParams] = useSearchParams();
// const redirectUrl = searchParams.get("redirect");
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const redirectUrl = searchParams.get("redirect");
const { handleToast } = useToastConfig();

const {
Expand All @@ -41,8 +39,6 @@ const SignIn = () => {
vapidKey: import.meta.env.VITE_FIREBASE_VAPID,
});

SetToken(fcmToken);

await postLogin({ email, password, fcmToken })
.then((loginData) => {
const { memberResponse, tokenResponse } = loginData;
Expand All @@ -51,12 +47,12 @@ const SignIn = () => {
// TODO: 임시로 localStorage에서 토큰 저장히지만 더 좋은 방법 찾기~!! 토스~!!
localStorage.setItem("accessToken", tokenResponse.accessToken);
localStorage.setItem("refreshToken", tokenResponse.refreshToken);
// if (redirectUrl) {
// navigate(redirectUrl, { replace: true });
// return;
// }
if (redirectUrl) {
navigate(redirectUrl, { replace: true });
return;
}

// navigate(PATH.ROOT, { replace: true });
navigate(PATH.ROOT, { replace: true });
})
.catch(() => {
handleToast(false, [<>아이디 혹은 비밀번호를 확인해주세요</>]);
Expand All @@ -68,7 +64,6 @@ const SignIn = () => {
<Link to="/">
<S.SignInLogo />
</Link>
<p>{token}</p>
<S.SignInInputContainer>
<S.SignInInputWrapper>
<S.SignInInputTitle>이메일</S.SignInInputTitle>
Expand Down

0 comments on commit 1f61a74

Please sign in to comment.