Skip to content
Snippets Groups Projects
Commit 1be511b5 authored by Hyun Woo Jeong's avatar Hyun Woo Jeong
Browse files

implement simple redirection

parent c159f90f
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File added
No preview for this file type
No preview for this file type
import {GoogleLogin} from "@react-oauth/google"; import {GoogleLogin} from "@react-oauth/google";
import {GoogleOAuthProvider} from "@react-oauth/google"; import {GoogleOAuthProvider} from "@react-oauth/google";
import { useNavigate, Navigate } from "react-router-dom";
import base64 from 'base-64'; import base64 from 'base-64';
import axios from 'axios'; import axios from 'axios';
/*
*/
const GoogleLoginButton = () => { const GoogleLoginButton = () => {
const clientId = '716858812522-rb0pfisq317unkh4so5hvbu16p19kqp8.apps.googleusercontent.com' const clientId = '716858812522-rb0pfisq317unkh4so5hvbu16p19kqp8.apps.googleusercontent.com'
let token = null; const navigate = useNavigate();
let payload = null; const goMain = () => {
navigate("/main");
}
return ( return (
<> <>
<GoogleOAuthProvider clientId={clientId}> <GoogleOAuthProvider clientId={clientId}>
...@@ -21,11 +30,15 @@ const GoogleLoginButton = () => { ...@@ -21,11 +30,15 @@ const GoogleLoginButton = () => {
RS256 : 암호화 알고리즘, JWT 서명할 때 사용한다고 함 RS256 : 암호화 알고리즘, JWT 서명할 때 사용한다고 함
*/ */
let datas = res.credential.split('.')
const obj = JSON.parse(base64.decode(datas[1])); let datas = res.credential.split('.')
const obj = JSON.parse(b64DecodeUnicode(datas[1]));
console.log(obj); console.log(obj);
commuTest(obj); let response = commuTest(obj);
console.log(response);
if (response) {
goMain();
}
}} }}
onFailure={(err) => { onFailure={(err) => {
console.log("Login Failed"); console.log("Login Failed");
...@@ -37,12 +50,31 @@ const GoogleLoginButton = () => { ...@@ -37,12 +50,31 @@ const GoogleLoginButton = () => {
); );
}; };
function b64DecodeUnicode(str) {
// Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str)
.split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
async function commuTest(payloadObj) { async function commuTest(payloadObj) {
const response = await axios({ const response = await axios({
url: 'http://localhost:8080/temp', // 통신할 웹문서 url: 'http://localhost:8080/login', // 통신할 웹문서
method: 'post', // 통신할 방식 method: 'post', // 통신할 방식
data: payloadObj data: payloadObj
}); });
console.log(response)
if (response.status === 200) {
return response.data;
}
else {
return null;
}
} }
export default GoogleLoginButton export default GoogleLoginButton
\ No newline at end of file
...@@ -3,6 +3,7 @@ import ReactDOM from "react-dom/client"; ...@@ -3,6 +3,7 @@ import ReactDOM from "react-dom/client";
import { BrowserRouter, Routes, Route } from "react-router-dom"; import { BrowserRouter, Routes, Route } from "react-router-dom";
import "./index.css"; import "./index.css";
import App from "./App"; import App from "./App";
import Main from "./Main";
const root = ReactDOM.createRoot(document.getElementById("root")); const root = ReactDOM.createRoot(document.getElementById("root"));
root.render( root.render(
...@@ -10,6 +11,7 @@ root.render( ...@@ -10,6 +11,7 @@ root.render(
<BrowserRouter> <BrowserRouter>
<Routes> <Routes>
<Route path="/" element={<App />} /> <Route path="/" element={<App />} />
<Route path="/main" element={<Main />} />
</Routes> </Routes>
</BrowserRouter> </BrowserRouter>
</React.StrictMode> </React.StrictMode>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment