Skip to content

Commit

Permalink
fix: login 모듈화 / homepage add login btn
Browse files Browse the repository at this point in the history
  • Loading branch information
Turtle-Hwan committed Aug 16, 2024
1 parent 27c8d5c commit 3036d83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
14 changes: 10 additions & 4 deletions src/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { SetStateAction, useState } from "react";
import { Link, useNavigate } from "react-router-dom";

import alarm from "@/assets/icon_alarm.svg";
import setting from "@/assets/icon_setting.svg";
import logoSpace from "@/assets/logo_space.svg";
import alarm from "@/assets/icon_alarm.svg";
import { BottomBtn } from "@/components/BottomBtn";
import bannerImage from "@/pages/HomePage/bannerImage.svg";
import bannerImageCover from "@/pages/HomePage/bannerImageCover.svg";
import next from "@/pages/HomePage/icon_next.svg";
import * as sty from "@/pages/HomePage/HomePage.styled";
import { SetStateAction, useState } from "react";
import { useNavigate } from "react-router-dom";
import next from "@/pages/HomePage/icon_next.svg";

const HomePage = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -44,6 +46,10 @@ const HomePage = () => {
<div className="tag">스페이서 20</div>
</sty.MainBanner>

<BottomBtn style={{ position: "relative" }}>
<Link to="/login">로그인</Link>
</BottomBtn>

<sty.NoticeContainer>
<sty.Settlement>
<div className="settlementTextContainer">
Expand Down
26 changes: 5 additions & 21 deletions src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import axios from "axios";

import { loginApi } from "@/apis";
import google from "@/assets/Login/icon_google.svg";
import kakao from "@/assets/Login/icon_kakao.svg";
import naver from "@/assets/Login/icon_naver.svg";
import axios from "axios";
import logoSpace from "@/assets/logo_space.svg";
import {
BtContainer,
Expand Down Expand Up @@ -40,26 +41,9 @@ const LoginPage = () => {

const handleLogin = async () => {
if (!isButtonActive) return;
try {
const response = await axios.post("/api/user/login", {
email: email,
password: password,
});

if (response.status === 200) {
const token = response.headers.authorization;
localStorage.setItem("jwt", token);
navigate("/dashboard");
} else {
console.error("로그인 실패:", response.data.message);
}
} catch (error) {
if (error instanceof Error) {
console.error("로그인 실패:", error.message);
} else {
console.error("로그인 실패:", error);
}
}
loginApi(email, password).then((res) =>
res.status === "OK" ? navigate("/") : alert("login error: " + res.message),
);
};

return (
Expand Down

0 comments on commit 3036d83

Please sign in to comment.