Skip to content

Commit

Permalink
브릿지 페이지추가 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ur2e committed Nov 11, 2022
1 parent 5bea2a1 commit 8dc020f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
10 changes: 2 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ import { BrowserRouter, Routes, Route } from "react-router-dom";
import Login from './component/loginpage/Login';
import Main from './component/mainpage/Main';
import MainSearch from './component/searchpage/MainSearch';
import { useSelector } from 'react-redux';
import { connect } from "react-redux";
import { useEffect, useState } from 'react';
import KakaoOauth from './component/loginpage/KakaoOauth';
// import Test from './component/loginpage/Test';
import Bridge from './component/loginpage/Bridge';

function App() {



return (
<div className='App'>
<BrowserRouter>
Expand All @@ -21,7 +15,7 @@ function App() {
<Route path="/main" element={<Main />} />
<Route path="/detail" element={<MainSearch/>}/>
<Route path="/oauth/kakao" element={<KakaoOauth/>}/>
{/* <Route path="/test" element={<Test/>}/> */}
<Route path="/bridge" element={<Bridge/>}/>
</Routes>
</BrowserRouter>
</div>
Expand Down
25 changes: 25 additions & 0 deletions src/component/loginpage/Bridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import axios from 'axios';

export default function Bridge(){
window.alert("브릿지도착");
axios({
method: "GET",
url: `http://localhost:8080/api/bridge`,
headers: {
'token': localStorage.getItem("token")
}
})
.then((res) => {
console.log("로그인 성공")
//history.replace("/main") // 토큰 받았았고 로그인됐으니 화면 전환시켜줌(메인으로)

document.location.href = "/main"

}).catch((err) => {
window.alert("토큰이 유효하지않음", err);
window.alert("로그인에 실패하였습니다.");

document.location.href = "/" // 로그인 실패하면 로그인화면으로 돌려보냄
})
return(<></>);
}
24 changes: 18 additions & 6 deletions src/component/loginpage/KakaoOauth.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import axios from 'axios';

export default function KakaoOauth(){
console.log("adfasdfasfdsadsfad")
let code = new URL(window.location.href).searchParams.get('code');
console.log(code);
console.log(code);
console.log(code);
console.log(code);
console.log(code);
console.log(code);
console.log(code);
console.log(code);
console.log(code);

axios({
method: "GET",
url: `http://localhost:8080/oauth/kakao?code=${code}`
url: `http://localhost:8080/api/oauth/kakao?code=${code}`
})
.then((res) => {
console.log(res); // 토큰이 넘어올 것임

console.log(res);
console.log(res.data);
const tokenData = res.data;
const accessToken = res.data.data.accessToken;

localStorage.setItem("token", accessToken); //예시로 로컬에 저장함

localStorage.setItem("token", JSON.stringify({tokenData})); //예시로 로컬에 저장함
console.log("로그인 성공")
//history.replace("/main") // 토큰 받았았고 로그인됐으니 화면 전환시켜줌(메인으로)
document.location.href = "/main"

}).catch((err) => {
console.log("소셜로그인 에러", err);
window.location.href = "/bridge"
}).catch((err) => {
console.log("소셜로그인 에러", err);
window.alert("로그인에 실패하였습니다.");

document.location.href = "/test" // 로그인 실패하면 로그인화면으로 돌려보냄
})

console.log("adfdaf")
return(<></>);
}

0 comments on commit 8dc020f

Please sign in to comment.