Skip to content

Commit

Permalink
[#4] feat : add google login
Browse files Browse the repository at this point in the history
  • Loading branch information
JZU0 committed Dec 20, 2023
1 parent 3e865b4 commit 74c5c6f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/components/LoginModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ const LoginModal = () => {
navigate("/test/0");
};

const handleGoogleLogin = () => {
window.location.href = `https://accounts.google.com/o/oauth2/v2/auth?
client_id=${process.env.REACT_APP_GOOGLE_AUTH_CLIENT_ID}
&redirect_uri=${process.env.REACT_APP_GOOGLE_AUTH_REDIRECT_URI}
&response_type=code
&scope=email profile`;
};

const handleKakaoLogin = () => {
window.location.href = kakaoURL;
};

return (
<Container>
<GoogleButton>
<GoogleButton onClick={handleGoogleLogin}>
<img src={google} alt="google" />
&nbsp;Google 계정으로 로그인
</GoogleButton>
Expand Down
43 changes: 29 additions & 14 deletions src/pages/ResultLoading/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { useRecoilValue } from "recoil";
import { axiosInstance } from "../../apis";
import { testState } from "../../store/atoms";
import { TestHeader } from "../../components";
import {
Expand All @@ -18,21 +18,36 @@ const TestPage = () => {
const testStateValue = useRecoilValue(testState);
const values = `${testStateValue.T}${testStateValue.F}${testStateValue.E}${testStateValue.I}${testStateValue.X}${testStateValue.O}`;
console.log(values);

const getResult = async () => {
try {
const response = await axiosInstance.get(
`/api/v1/test-result?result=${values}`,
);
console.log(response);
} catch (err) {
console.error(err);
}
};
const navigate = useNavigate();

useEffect(() => {
getResult();
}, []);
const routeMap = {
303030: "/one",
212121: "/one",
"031203": "/two",
120312: "/two",
"030330": "/three",
121221: "/three",
"033030": "/four",
122121: "/four",
301203: "/five",
210312: "/five",
300330: "/six",
211221: "/six",
"032103": "/seven",
123012: "/seven",
302103: "/eight",
213012: "/eight",
};

// Get the route based on the values
const route = routeMap[values];

// Redirect to the appropriate page after 2 seconds
setTimeout(() => {
navigate(route);
}, 2000);
}, [navigate, values]);

return (
<>
Expand Down

0 comments on commit 74c5c6f

Please sign in to comment.