Skip to content

Commit

Permalink
Merge pull request #34 from Soongsil-CoffeeChat/feat/#27
Browse files Browse the repository at this point in the history
[Feat] 상태 관리 기능 추가(로그인 모달/ 유저 토큰 값 변경)
  • Loading branch information
candosh authored Jun 2, 2024
2 parents 19d0da8 + f814165 commit 2d89549
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/pages/login/LoginCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function LoginCallback() {
}
);

console.log("응답 데이터:", response);
// console.log("응답 헤더:", response.headers);

if (response.status === 200) {
const accessToken = response.headers["access"];
Expand All @@ -37,6 +37,8 @@ function LoginCallback() {
token: accessToken,
});

localStorage.setItem("isLoggedIn", "true");

switch (loginStatus) {
case "signup":
navigate("/signup");
Expand All @@ -62,11 +64,6 @@ function LoginCallback() {
} else {
console.error("알 수 없는 오류 발생:", error);
}
setAuth({
isLoggedIn: false,
username: null,
token: null,
});
}
};

Expand Down
14 changes: 10 additions & 4 deletions src/pages/main/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useEffect, useState } from "react";
import * as styles from "./main.styles";
import { useNavigate } from "react-router-dom";
import { authState } from "../../atoms/authState";
import { useRecoilValue } from "recoil";
import LeftButton from "../../assets/LeftButton.svg";
import RightButton from "../../assets/RightButton.svg";

Expand All @@ -17,13 +19,17 @@ function Main() {
const [mentorData, setMentorData] = useState<MentorData[] | null>(null);
const navigate = useNavigate();
const [currentIndex, setCurrentIndex] = useState(0);
const { token } = useRecoilValue(authState);

useEffect(() => {}, [activeButtons]);
useEffect(() => {
const isLoggedIn = localStorage.getItem("isLoggedIn") === "true";
if (!isLoggedIn) {
navigate("/login");
}
}, [navigate]);

useEffect(() => {
const token = process.env.REACT_APP_TOKEN;
// process.env.REACT_APP_TOKEN;
const url = `https://cogo.run/api/v1/mentor/BE`;
const url = `https://cogo.life/api/v1/mentor/BE`;

fetch(url, {
method: "GET",
Expand Down
9 changes: 4 additions & 5 deletions src/pages/signup/signup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios from "axios";
import { useNavigate } from "react-router-dom";
import { useState, ChangeEvent, useEffect } from "react";
import { authState } from "../../atoms/authState";
import { useRecoilValue } from "recoil";
import LeftArrow from "../../assets/ArrowLeft.svg";
import BlackLine from "../../assets/BlackLine.svg";
import * as styles from "./signup.styles";
Expand All @@ -9,6 +11,7 @@ import * as styles from "./signup.styles";

function SignUp() {
const navigate = useNavigate();
const { token } = useRecoilValue(authState);
const [email, setEmail] = useState<string>("");
const [domain, setDomain] = useState<string>("@self");
const [code, setCode] = useState<string>("");
Expand All @@ -35,9 +38,7 @@ function SignUp() {
navigate("/");
};

useEffect(() => {
// 클릭한 분야 변경 시 데이터 가져오기
}, [activeButton]);
useEffect(() => {}, [activeButton]);

const handleButtonClick = (buttonName: string) => {
setActiveButton((prev) => (prev === buttonName ? "" : buttonName));
Expand All @@ -52,7 +53,6 @@ function SignUp() {
};

const sendEmail = () => {
const token = process.env.REACT_APP_TOKEN;
const link = getEmailLink();

axios
Expand Down Expand Up @@ -83,7 +83,6 @@ function SignUp() {
};

const submitSignUp = () => {
const token = process.env.REACT_APP_TOKEN;
const url = "https://cogo.life/api/v1/user/join/mentee";
const userData = {
email: `${email}${domain}`,
Expand Down

0 comments on commit 2d89549

Please sign in to comment.