Skip to content

Commit

Permalink
Merge pull request #239 from SCBJ-7/feature/#236-render-token
Browse files Browse the repository at this point in the history
[#236] 토큰 임시로 렌더링 되도록
  • Loading branch information
im-na0 authored Jan 26, 2024
2 parents 1b0bed7 + 72db53c commit e23c6e1
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/pages/signInPage/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import * as S from "./SignIn.style";
import { useForm } from "react-hook-form";
import { Link, useNavigate, useSearchParams } from "react-router-dom";
import { Link } 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 navigate = useNavigate();
const [searchParams] = useSearchParams();
const redirectUrl = searchParams.get("redirect");
const [token, SetToken] = useState("");
// const navigate = useNavigate();
// const [searchParams] = useSearchParams();
// const redirectUrl = searchParams.get("redirect");
const { handleToast } = useToastConfig();

const {
Expand All @@ -30,17 +32,17 @@ const SignIn = () => {
},
});

let fcmToken = "";

const handleOnSubmit = async (data: FormValues) => {
const { email, password } = data;

const messaging = getMessaging(app);

fcmToken = await getToken(messaging, {
const fcmToken = await getToken(messaging, {
vapidKey: import.meta.env.VITE_FIREBASE_VAPID,
});

SetToken(fcmToken);

await postLogin({ email, password, fcmToken })
.then((loginData) => {
const { memberResponse, tokenResponse } = loginData;
Expand All @@ -49,12 +51,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 @@ -66,7 +68,7 @@ const SignIn = () => {
<Link to="/">
<S.SignInLogo />
</Link>
<p>{fcmToken}</p>
<p>{token}</p>
<S.SignInInputContainer>
<S.SignInInputWrapper>
<S.SignInInputTitle>이메일</S.SignInInputTitle>
Expand Down

0 comments on commit e23c6e1

Please sign in to comment.