@@ -160,7 +186,7 @@ const RegisterForm = () => {
-
Password
diff --git a/src/service/authentication/authentication.context.js b/src/service/authentication/authentication.context.js
index 1e6d1e2..69b474b 100644
--- a/src/service/authentication/authentication.context.js
+++ b/src/service/authentication/authentication.context.js
@@ -1,82 +1,132 @@
import React, { useState, createContext, useEffect } from "react";
-import { PostSendVerifyEmail, PostVerifyEmail, UsersCheckDuplicate, UsersLogin, UsersSignup, loginHandler } from "./authentication.service";
+import {
+ GetEmailWithGHToken,
+ PermitAllEmailLogin,
+ PostSendVerifyEmail,
+ PostVerifyEmail,
+ UsersCheckDuplicate,
+ UsersLogin,
+ UsersSignup,
+ loginHandler,
+ permitAllEmailLogin,
+} from "./authentication.service";
export const AuthenticationContext = createContext();
export const AuthenticationContextProvider = ({ children }) => {
- const [userToken, setUserToken] = useState(JSON.parse(sessionStorage.getItem("userToken")));
- const [isLogin, setIsLogin] = useState(JSON.parse(sessionStorage.getItem("isLogin")));
- const [userData, setUserData] = useState(null);
+ const [userToken, setUserToken] = useState(JSON.parse(sessionStorage.getItem("userToken")));
+ const [isLogin, setIsLogin] = useState(JSON.parse(sessionStorage.getItem("isLogin")));
+ const [userData, setUserData] = useState(JSON.parse(sessionStorage.getItem("userData")));
- const OnLogin = async (userEmail, userPw) => {
- const res = await UsersLogin(userEmail, userPw);
- console.log(res);
- sessionStorage.setItem("isLogin", true);
- setIsLogin(true);
- alert("로그인 되었습니다!");
- };
+ const OnLogin = async (userEmail, userPw) => {
+ const res = await UsersLogin(userEmail, userPw);
+ console.log(res);
+ if (res.data === "login failed") {
+ alert("이메일과 비밀번호를 다시 확인해주세요.");
+ } else {
+ setUserToken(res.data);
+ setUserData(JSON.parse(atob(res.data.split(".")[1])));
+ sessionStorage.setItem("userData", JSON.stringify(atob(res.data.split(".")[1])));
+ sessionStorage.setItem("userToken", JSON.stringify(res.data));
+ sessionStorage.setItem("isLogin", true);
+ setIsLogin(true);
+ alert("로그인 되었습니다!");
+ }
+ };
- const OnLogout = () => {
- setUserToken("");
- window.location.reload();
- setIsLogin(false);
- sessionStorage.removeItem("isLogin");
- alert("로그아웃 되었습니다!");
- };
+ const OnLogout = () => {
+ setUserToken("");
+ window.location.reload();
+ setIsLogin(false);
+ sessionStorage.removeItem("isLogin");
+ sessionStorage.removeItem("userData");
+ sessionStorage.removeItem("userToken");
+ alert("로그아웃 되었습니다!");
+ };
- const OnRegister = async (email, userPW, userNN) => {
- const res = await UsersSignup(email, userPW, userNN)
- .then(alert(`회원가입이 완료되었습니다`))
- .catch((e) => alert(e));
- console.log(res);
- };
+ const OnRegister = async (email, userPW, userNN) => {
+ const res = await UsersSignup(email, userPW, userNN)
+ .then(alert(`회원가입이 완료되었습니다`))
+ .catch((e) => alert(e));
+ console.log(res);
+ };
- const OnDupNNCheck = async (userNN) => {
- const res = await UsersCheckDuplicate(userNN)
- .then((res) => {
- console.log(res.data);
- return res.data;
- })
- .catch((e) => alert(e));
+ const OnDupNNCheck = async (userNN) => {
+ const res = await UsersCheckDuplicate(userNN)
+ .then((res) => {
+ console.log(res.data);
+ return res.data;
+ })
+ .catch((e) => alert(e));
- return res;
- };
+ return res;
+ };
- const OnEmailVerifySend = async (email) => {
- const res = await PostSendVerifyEmail(email)
- .then((res) => {
- console.log(res.data);
- alert(res.data);
+ const OnEmailVerifySend = async (email) => {
+ const res = await PostSendVerifyEmail(email)
+ .then((res) => {
+ console.log(res.data);
+ alert(res.data);
+ return res;
+ })
+ .catch((e) => alert(e));
return res;
- })
- .catch((e) => alert(e));
- return res;
- };
- const OnEmailVerify = async (email, code) => {
- const res = await PostVerifyEmail(email, code)
- .then((res) => {
- console.log(res);
- alert(res.data);
- if (res.data == "Email is Verified Successfully") {
- return true;
- } else return false;
- })
- .catch((e) => alert(e));
- return res;
- };
- return (
-
- {children}
-
- );
+ };
+ const OnEmailVerify = async (email, code) => {
+ const res = await PostVerifyEmail(email, code)
+ .then((res) => {
+ console.log(res);
+ alert(res.data);
+ if (res.data == "Email is Verified Successfully") {
+ return true;
+ } else return false;
+ })
+ .catch((e) => alert(e));
+ return res;
+ };
+
+ const OnGHLogin = async (accessToken) => {
+ try {
+ const ghEmail = await GetEmailWithGHToken(accessToken);
+ console.log(ghEmail);
+ if (ghEmail === null) {
+ alert("이메일을 알 수 없는 깃허브 계정입니다");
+ }
+ const emailCheck = await PermitAllEmailLogin(ghEmail);
+ console.log(emailCheck);
+ const res = emailCheck.data.split(" ");
+ if (res[0] === "email") {
+ alert("회원가입창으로 이동합니다 닉네임을 설정해주세요!");
+ console.log("email");
+ return { type: "email", result: res[1] };
+ } else {
+ console.log("jwt : ", res[1]);
+ setUserToken(res[1]);
+ setUserData(JSON.parse(atob(res[1].split(".")[1])));
+ sessionStorage.setItem("userData", JSON.stringify(atob(res[1].split(".")[1])));
+ sessionStorage.setItem("userToken", JSON.stringify(res[1]));
+ sessionStorage.setItem("isLogin", true);
+ setIsLogin(true);
+ alert("로그인 되었습니다!");
+ return { type: "jwt", result: res[1] };
+ }
+ } catch {}
+ };
+ return (
+
+ {children}
+
+ );
};
diff --git a/src/service/authentication/authentication.service.tsx b/src/service/authentication/authentication.service.tsx
index 7e385c3..f8619a6 100644
--- a/src/service/authentication/authentication.service.tsx
+++ b/src/service/authentication/authentication.service.tsx
@@ -1,100 +1,119 @@
import axios, { AxiosError, AxiosResponse } from "axios";
-const CLIENT_ID = process.env.REACT_APP_CLIENT_ID;
-const USER_API_URL = process.env.REACT_APP_USER_API_URL;
-
-// 깃허브 로그인창으로 다이렉트 해주는 함수
-export const GitHubLoginRequestHandler = () => {
- // TODO: GitHub로부터 사용자 인증을 위해 GitHub로 이동해야 합니다. 적절한 URL을 입력하세요.
- // OAuth 인증이 완료되면 authorization code와 함께 callback url로 리디렉션 합니다.
- return window.location.assign(`https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}`);
- //로그인 요청을 보내면 github auth server에서 redirect 로 callback, 그리고 auth code를 전달
-};
+const API_URL = process.env.REACT_APP_ALOG_API_URL;
// EMAIL
export const PostVerifyEmail = (email: string, code: string) => {
- const verifyData = {
- email: email,
- code: code,
- };
- console.log(verifyData);
- const signUpResult: Promise
= axios
- .post(`${USER_API_URL}/api/users/emails/verify`, verifyData)
- .then((res: AxiosResponse) => {
- return res;
- })
- .catch((err: AxiosError) => {
- throw err;
- });
- return signUpResult;
+ const verifyData = {
+ email: email,
+ code: code,
+ };
+ console.log(verifyData);
+ const signUpResult: Promise = axios
+ .post(`${API_URL}/api/users/permit-all/emails/verify`, verifyData)
+ .then((res: AxiosResponse) => {
+ return res;
+ })
+ .catch((err: AxiosError) => {
+ throw err;
+ });
+ return signUpResult;
};
export const PostSendVerifyEmail = (email: string) => {
- const emailString = email.replace("@", "%40");
- const sendResult: Promise = axios
- .post(`${USER_API_URL}/api/users/emails/send?EmailTo=${emailString}`)
- .then((res: AxiosResponse) => {
- return res;
- })
- .catch((err: AxiosError) => {
- throw err;
- });
- return sendResult;
+ const emailString = email.replace("@", "%40");
+ const sendResult: Promise = axios
+ .post(`${API_URL}/api/users/permit-all/emails/send?EmailTo=${emailString}`)
+ .then((res: AxiosResponse) => {
+ return res;
+ })
+ .catch((err: AxiosError) => {
+ throw err;
+ });
+ return sendResult;
};
// USER AUTH
export const UsersSignup = (email: string, userPw: string, userNN: string) => {
- const SignUpData = {
- userPw: userPw,
- userNN: userNN,
- email: email,
- };
- const signUpResult: Promise = axios
- .post(`${USER_API_URL}/api/users/signup`, SignUpData)
- .then((res: AxiosResponse) => {
- return res;
- })
- .catch((err: AxiosError) => {
- throw err;
- });
- return signUpResult;
+ const SignUpData = {
+ userPw: userPw,
+ userNN: userNN,
+ email: email,
+ };
+ const signUpResult: Promise = axios
+ // .post(`${API_URL}/api/users/signup`, SignUpData)
+ .post(`${API_URL}/api/users/permit-all/signup`, SignUpData)
+ .then((res: AxiosResponse) => {
+ return res;
+ })
+ .catch((err: AxiosError) => {
+ throw err;
+ });
+ return signUpResult;
};
export const UsersLogin = (userEmail: string, userPassword: string): Promise => {
- const loginData = {
- userEmail: userEmail,
- userPw: userPassword,
- };
+ const loginData = {
+ userEmail: userEmail,
+ userPw: userPassword,
+ };
- const loginResult: Promise = axios
- .post(`${USER_API_URL}/api/users/login`, loginData)
- .then((res: AxiosResponse) => {
- return res;
- })
- .catch((err: AxiosError) => {
- throw err;
- });
- return loginResult;
+ const loginResult: Promise = axios
+ .post(`${API_URL}/auth/permit-all/login`, loginData)
+ .then((res: AxiosResponse) => {
+ return res;
+ })
+ .catch((err: AxiosError) => {
+ throw err;
+ });
+ return loginResult;
};
export const UsersInfo = () => {
- return null;
+ return null;
};
export const UsersCheckDuplicate = (userNN: string) => {
- const checkDupResult: Promise = axios
- .get(`${USER_API_URL}/api/users/duplicated/${userNN}`)
- .then((res: AxiosResponse) => {
- return res;
- })
- .catch((err: AxiosError) => {
- throw err;
- });
- return checkDupResult;
+ const checkDupResult: Promise = axios
+ .get(`${API_URL}/api/users/permit-all/duplicated/${userNN}`)
+ .then((res: AxiosResponse) => {
+ return res;
+ })
+ .catch((err: AxiosError) => {
+ throw err;
+ });
+ return checkDupResult;
};
export const UsersDelete = () => {
- return null;
+ return null;
+};
+
+export const GetEmailWithGHToken = (accessToken: string) => {
+ const res: Promise = axios
+ .get(`${API_URL}/auth/permit-all/github/access-token?accessToken=${accessToken}`)
+ .then((res: AxiosResponse) => {
+ return res.data;
+ })
+ .catch((err: AxiosError) => {
+ throw err;
+ });
+ return res;
+};
+export const PermitAllEmailLogin = (email: string) => {
+ const params = {
+ email: email,
+ };
+ const res = axios
+ .get(`${API_URL}/auth/permit-all/email-login`, { params })
+ .then((response) => {
+ console.log(response);
+ return response;
+ })
+ .catch((error) => {
+ console.error(error);
+ });
+ return res;
};
diff --git a/src/service/authentication/github.service.tsx b/src/service/authentication/github.service.tsx
new file mode 100644
index 0000000..d9fd24c
--- /dev/null
+++ b/src/service/authentication/github.service.tsx
@@ -0,0 +1,53 @@
+import React from "react";
+import axios from "axios";
+
+const CLIENT_ID = process.env.REACT_APP_CLIENT_ID!;
+const CLIENT_SECRET = process.env.REACT_APP_CLIENT_SECRET!;
+
+const GITHUB_AUTH_CODE_SERVER = "/login/oauth/authorize";
+const GITHUB_AUTH_TOKEN_SERVER = "/login/oauth/access_token";
+const GITHUB_API_SERVER = "/user";
+
+// 깃허브 로그인창으로 다이렉트 해주는 함수
+export const GitHubLoginRequestHandler = () => {
+ // TODO: GitHub로부터 사용자 인증을 위해 GitHub로 이동해야 합니다. 적절한 URL을 입력하세요.
+ // OAuth 인증이 완료되면 authorization code와 함께 callback url로 리디렉션 합니다.
+ return window.location.assign(`https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}`);
+ //로그인 요청을 보내면 github auth server에서 redirect 로 callback, 그리고 auth code를 전달
+};
+
+export const GithubAuth = async (code: string) => {
+ console.log(code);
+ const clientId = CLIENT_ID;
+ const clientSecret = CLIENT_SECRET;
+
+ const body = new URLSearchParams({
+ client_id: clientId,
+ client_secret: clientSecret,
+ code: code,
+ });
+
+ // 요청 헤더를 설정합니다.
+ const headers = {
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ };
+
+ // axios.post 메소드를 사용하여 요청을 보냅니다.
+ const res = await axios
+ .post(`${GITHUB_AUTH_TOKEN_SERVER}`, body, { headers: headers })
+ .then((response) => {
+ // 응답을 로그로 출력합니다.
+ console.log("response : ", response.data);
+ // 응답 데이터에서 access_token을 추출합니다.
+ const accessToken = response.data.access_token;
+ // 필요한 경우 추가 로직을 여기에 추가할 수 있습니다.
+
+ return accessToken;
+ })
+ .catch((error) => {
+ // 에러를 로그로 출력합니다.
+ console.error("error : ", error.message);
+ });
+ return res;
+};
diff --git a/src/setupProxy.js b/src/setupProxy.js
new file mode 100644
index 0000000..4257182
--- /dev/null
+++ b/src/setupProxy.js
@@ -0,0 +1,18 @@
+const { createProxyMiddleware } = require("http-proxy-middleware");
+
+// src/setupProxy.js
+
+module.exports = function (app) {
+ app.use(
+ createProxyMiddleware("/login", {
+ target: "https://github.com",
+ changeOrigin: true,
+ })
+ );
+ app.use(
+ createProxyMiddleware("/user", {
+ target: "https://api.github.com",
+ changeOrigin: true,
+ })
+ );
+};
diff --git a/tsconfig.json b/tsconfig.json
index 9d379a3..139d543 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,4 +1,24 @@
{
+<<<<<<< HEAD
+ "compilerOptions": {
+ "target": "es5",
+ "lib": ["dom", "dom.iterable", "esnext"],
+ "allowJs": true,
+ "skipLibCheck": true,
+ "esModuleInterop": true,
+ "allowSyntheticDefaultImports": true,
+ "strict": true,
+ "forceConsistentCasingInFileNames": true,
+ "noFallthroughCasesInSwitch": true,
+ "module": "esnext",
+ "moduleResolution": "node",
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "noEmit": true,
+ "jsx": "react-jsx"
+ },
+ "include": ["src"]
+=======
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
@@ -17,4 +37,5 @@
"jsx": "react-jsx"
},
"include": ["src"]
+>>>>>>> 00b1bc3285f2d374a1b302a09a08a7d7255b3b16
}