Skip to content

Commit

Permalink
Merge pull request #82 from next-petree/feat_login
Browse files Browse the repository at this point in the history
Feat login
  • Loading branch information
ChanghyeonO authored Jan 2, 2024
2 parents 2d747d2 + 288003a commit f854637
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
10 changes: 4 additions & 6 deletions src/component/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ const Header = () => {
const profileImg = useAppSelector(selectBreederProfile);

const handleClick = async () => {
if(isLoggedIn) {
navigate("/mypage/modifyauth")
}
else {
if (isLoggedIn) {
navigate("/mypage/modifyauth");
} else {
const answer = await Swal.fire({
...alertList.infoMessage("λ‘œκ·ΈμΈμ„ λ¨Όμ € μ§„ν–‰ν•΄μ£Όμ„Έμš”"),
width: "350px",
});
if(answer) navigate("/login");
if (answer) navigate("/login");
}
};

Expand Down
24 changes: 8 additions & 16 deletions src/component/KakaoCallback/KakaoCallback.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { get } from "../../api/api";
import { getToken } from "../../api/token";
Expand All @@ -20,7 +20,6 @@ interface KakaoLoginResponse {
const KakaoCallback = () => {
const location = useLocation();
const navigate = useNavigate();
const [error, setError] = useState("");

useEffect(() => {
const code = new URL(document.location.toString()).searchParams.get("code");
Expand All @@ -37,24 +36,22 @@ const KakaoCallback = () => {

try {
const response = await get<KakaoLoginResponse>(
`${REACT_APP_API_URL}/oauth/kakao/callback?code=${code}`,
`${REACT_APP_API_URL}oauth/kakao/callback?code=${code}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
);

if (response.data.status === "SUCCESS") {
localStorage.setItem("accessToken", response.data.data.accessToken);
localStorage.setItem("refreshToken", response.data.data.refreshToken);
navigate("/");
} else {
const errorMessage =
typeof response.data.data === "string"
? response.data.data
: "λ‘œκ·ΈμΈμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.";
await Swal.fire(alertList.errorMessage(errorMessage));
setError("λ‘œκ·ΈμΈμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.");
} else if (response.data.status === "FAIL") {
Swal.fire(alertList.errorMessage("μΉ΄μΉ΄μ˜€μ— μ—°λ™λœ 계정이 μ—†μŠ΅λ‹ˆλ‹€."));
navigate("/login");
return;
}
} catch (error) {
console.error("Kakao login error:", error);
Expand All @@ -65,12 +62,7 @@ const KakaoCallback = () => {
}
};

return (
<div>
카카였 둜그인 쀑...
{error && <div>{error}</div>}
</div>
);
return <div>카카였 둜그인 쀑...</div>;
};

export default KakaoCallback;
27 changes: 26 additions & 1 deletion src/component/MyPage/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useLocation, useNavigate } from "react-router-dom";
import Swal from "sweetalert2";
import alertList from "../../../utils/Swal1";
import { removeToken } from "../../../api/token";
import {
AuthDeleteContainer,
CategoryContent,
CategoryContainer,
Main,
NavBarContainer,
LogoutContainer,
} from "./Styles1";

export const NavCategory = [
Expand Down Expand Up @@ -38,6 +42,24 @@ const Navbar = () => {
const DeleteAccount = () => {
navigation("/mypage/remove-account");
};

const handleLogout = async () => {
const answer = await Swal.fire(
alertList.doubleCheckMessage("λ‘œκ·Έμ•„μ›ƒ ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?"),
);

if (answer.isConfirmed) {
try {
removeToken("accessToken");
removeToken("refreshToken");
navigation("/");
Swal.fire(alertList.successMessage("λ‘œκ·Έμ•„μ›ƒμ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€"));
} catch (error) {
console.error("λ‘œκ·Έμ•„μ›ƒ 쀑 였λ₯˜ λ°œμƒ:", error);
}
}
};

return (
<NavBarContainer>
<Main>
Expand All @@ -50,9 +72,12 @@ const Navbar = () => {
<CategoryContent>{category.name}</CategoryContent>
</CategoryContainer>
))}
<LogoutContainer onClick={handleLogout}>
<CategoryContent style={{ color: "red" }}>λ‘œκ·Έμ•„μ›ƒ</CategoryContent>
</LogoutContainer>
</Main>
<AuthDeleteContainer onClick={DeleteAccount}>
<CategoryContent>νšŒμ› νƒˆν‡΄</CategoryContent>
<CategoryContent>νšŒμ›νƒˆν‡΄</CategoryContent>
</AuthDeleteContainer>
</NavBarContainer>
);
Expand Down
15 changes: 15 additions & 0 deletions src/component/MyPage/Navbar/Styles1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,24 @@ export const AuthDeleteContainer = styled.div`
justify-content: center;
align-items: center;
cursor: pointer;
&:hover {
background-color: #f5f5f5;
border-radius: 0 0 20px 20px;
}
`;

export const LogoutContainer = styled.div`
width: 100%;
height: 8%;
padding: 1.5vh 0;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
&:hover {
background-color: #f5f5f5;
border-radius: 0 0 20px 20px;
}
`;

export const LogoutButton = styled.div``;

0 comments on commit f854637

Please sign in to comment.