Skip to content

Commit

Permalink
feat: 소셜 로그인 구현(Google, Kakao) #111
Browse files Browse the repository at this point in the history
구글 및 카카오를 이용한 로그인 및 로그아웃 로직 구현
  • Loading branch information
NowVic99 authored Jan 27, 2023
2 parents 2937e6a + 091f6b5 commit 77e0d3a
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 114 deletions.
2 changes: 1 addition & 1 deletion project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@
"@types/styled-components": "^5.1.26",
"styled-components": "^5.3.6"
},
"proxy": "http://pikcha36.o-r.kr:8080"
"proxy" : "http://pikcha36.o-r.kr:8080"
}
2 changes: 2 additions & 0 deletions project/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RecoilRoot } from "recoil";
import DetailPost from "./pages/DetailPost";
import MyPage from "./pages/MyPage";
import EditPost from "./pages/EditPost ";
import Oauth from "./pages/Oauth"

function App() {

Expand All @@ -34,6 +35,7 @@ function App() {
<Route path="/posts/detail/:id" element={<DetailPost />} />
<Route path="/mypage" element={<MyPage />} />
<Route path="/edit/:id" element={<EditPost />} />
<Route path="/oauth" element={<Oauth />} />
</Routes>
</RecoilRoot>
</BrowserRouter>
Expand Down
59 changes: 0 additions & 59 deletions project/src/components/GoogleLogin.js

This file was deleted.

1 change: 0 additions & 1 deletion project/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const SearchBar = lazy(() => import("./SearchBar"));

const IMG_SRC =
"https://drive.google.com/uc?id=1OmsgU1GLU9iUBYe9ruw_Uy1AcrN57n4g";
const isLoggedIn = true;

const HeaderTopBar = () => {
const navigate = useNavigate();
Expand Down
53 changes: 11 additions & 42 deletions project/src/components/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import styled from "styled-components";
import ButtonForm from "./Button";
import Axios from "axios";
Expand All @@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom";
import { useRecoilState } from "recoil";
import { LoginState, AuthToken, LoggedUser } from "../recoil/state";


interface TextProps {
fontSize: string;
color: string;
Expand Down Expand Up @@ -304,38 +305,12 @@ const Login = () => {
}
};

const GoogleHandler = () => {
axios
// .post("/login/oauth2/code/google", {
// username: loginemail,
// password: loginpassword,
// })
.get("oauth2/authorization/google", {
// headers: {
// "Content-Type" : "application/x-www-form-urlencoded"
// }
})
.then((res) => console.log(res))
.catch((err) => console.error(err));
};

const googlelogin = () => {
window.location.href =
"http://localhost:8090/oauth2/authorization/google";
const query = window.location.search;
console.log("이게무야2", query);
const param = new URLSearchParams(query);
console.log(param);
};

const kakaologin = () => {
window.location.href =
"http://localhost:8090/oauth2/authorization/kakao"
const query = window.location.search;
console.log("이게무야2", query);
const param = new URLSearchParams(query);
console.log(param);
};
const googleLogin = () => {
window.location.href = "http://pikcha36.o-r.kr:8080/oauth2/authorization/google";
};
const kakaologin = () => {
window.location.href = "http://pikcha36.o-r.kr:8080/oauth2/authorization/kakao";
};

return (
<Wrapper>
Expand Down Expand Up @@ -363,15 +338,9 @@ const Login = () => {
로그인
</TextStyle>
<CustomPadding padding="30px 0px 0px 0px"></CustomPadding>
<button onClick={kakaologin}>카카</button>
<button onClick={googlelogin}>구글</button>



<GButton>G</GButton>



<button onClick={kakaologin}>카카2</button>
<button onClick={googleLogin}>구글3</button>
<GButton onClick={googleLogin}>G</GButton>
<TextStyle color="#6154F8" fontSize="22px" fontweight="bold">
SNS 계정으로 로그인
</TextStyle>
Expand Down
4 changes: 2 additions & 2 deletions project/src/components/PostBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ const PostBox = ({postData}:any) => {
postData.map((el:any)=>{
return(
<PostCard key={el.postId}>
<div><img src={el.picture}></img></div>
<div><img src={el.picture} alt="" /></div>
<div>
<div>
<img src={el.picture}></img>
<img src={el.picture} alt=""/>
<div>
<div>{el.username}</div>
<span>{(el.createdAt).slice(0,10)}</span>
Expand Down
4 changes: 2 additions & 2 deletions project/src/components/PostCardComponent.tsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ const PostCardComponent = ({
<PostCard key={post.postId} width={width}>
<div>
<img
src={post.picture}
src={post.picture} alt=""
onClick={() => navigate(`/posts/detail/${post.postId}`)}
></img>
</div>
<div>
<div>
<img src={post.picture}></img>
<img src={post.picture} alt=""/>
<div>
<div>{post.username}</div>
<span>{post.createdAt.slice(0, 10)}</span>
Expand Down
2 changes: 1 addition & 1 deletion project/src/pages/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ const MyPage = () => {
<MyPageContainer>
<MyPageUserInfo>
<form>
<img src="http://drive.google.com/uc?export=view&amp;id=1OmsgU1GLU9iUBYe9ruw_Uy1AcrN57n4g" />
<img src="http://drive.google.com/uc?export=view&amp;id=1OmsgU1GLU9iUBYe9ruw_Uy1AcrN57n4g" alt="" />
<div>
개구리 뒷다리 <TfiPencil />
</div>
Expand Down
37 changes: 37 additions & 0 deletions project/src/pages/Oauth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import {
useRecoilState,
} from "recoil";
import { LoginState, AuthToken, LoggedUser } from "../recoil/state";

const Oauth = () => {
const navigate = useNavigate();
const [isLogin, setIsLogin] = useRecoilState(LoginState);
const [isToken, setToken] = useRecoilState(AuthToken);

useEffect(() => {
const query = window.location.search;
const param = new URLSearchParams(query);

const getaccessToken = param.get("accessToken");
const getId = param.get("id");

// console.log("팔람팔람팔람:",param)
// console.log("퀄퀄:",query)
// console.log("토토토토토토 :", getaccessToken)

localStorage.setItem("Authorization",`Bearer ${getaccessToken}`)
localStorage.setItem("memberId", `${getId}`)
localStorage.setItem("loginStatus",`true`)
setIsLogin(true);
setToken(`Bearer ${getaccessToken}`);

window.location.replace("/")
;
} ,[]
)
return <></>
};

export default Oauth;
7 changes: 1 addition & 6 deletions project/src/utils/axiosinstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ axios.interceptors.request.use(
(config) => {
// const accessToken = localStorage.getItem("Authorization");
// axios.defaults.headers.common["Authorization"] = accessToken;

return config;
},
(error) => {
Expand All @@ -27,7 +26,7 @@ axios.interceptors.response.use(
response: { status },
} = error;
if (status === 400 && error.response.data.message === "Token Expired") {
const originalRequest = config;
const originalRequest = config;
axios.defaults.headers.common["Authorization"] = null;
const memberId = localStorage.getItem("memberId");
const { data } = await axios.get(`/token/refresh/${memberId}`);
Expand All @@ -54,10 +53,6 @@ axios.interceptors.response.use(
alert("로그인 시간 만료.")
window.location.replace("/login")
}
if(status === 403){

}

console.log("response error", error);
return Promise.reject(error);
}
Expand Down

0 comments on commit 77e0d3a

Please sign in to comment.