Skip to content

Commit

Permalink
๐Ÿงช Test: oAuth ํ…Œ์ŠคํŠธ
Browse files Browse the repository at this point in the history
๐Ÿงช Test: oAuth ํ…Œ์ŠคํŠธ
  • Loading branch information
Youngbae1126 authored Mar 7, 2024
2 parents 10e502c + 38256be commit f6dc624
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 53 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# misc
.DS_Store
.env.local
.env.development
.env.development.local
.env.test.local
.env.production.local
Expand All @@ -23,4 +24,5 @@ yarn-debug.log*
yarn-error.log*

localhost-key.pem
localhost.pem
localhost.pem

59 changes: 7 additions & 52 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React, { useContext, useEffect, useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import axios from 'axios';

// SERVICE
import api from '../services/api';

// COMPONENTS
import Btn from '../components/Button';

Expand Down Expand Up @@ -59,54 +62,6 @@ export default function Login() {
}
};

// ๋กœ๊ทธ์ธ ์š”์ฒญ, login
// useEffect(() => {
// const postFetch = async () => {
// try {
// localStorage.clear();
// const result = await login(id, pwd);
// console.log("result.data", result.data);
// const token = result.headers.authorization;
// // console.log(token);
// localStorage.setItem("token", token); // ์ „์ฒด ํ† ํฐ ์ €์žฅ
// localStorage.setItem("accessToken", token.split(" ")[1]); // ์•ก์„ธ์Šค ํ† ํฐ ์ €์žฅ
// localStorage.setItem("refreshToken", token.split(" ")[2]); // ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ ์ €์žฅ
// // router('/main'); // ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ์ด๋™
// } catch (error) {
// console.error("๋กœ๊ทธ์ธ ์š”์ฒญ ์‹คํŒจ", error);
// }
// };
// postFetch();
// }, []);

// hello ์š”์ฒญ
// useEffect(() => {
// const token = localStorage.getItem("token"); // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์—์„œ ์ „์ฒด ํ† ํฐ ์ถ”์ถœ
// const accessToken = localStorage.getItem("accessToken"); // ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์•ก์„ธ์Šค ํ† ํฐ๋งŒ ๋”ฐ๋กœ ์ถ”์ถœ

// if (token) {
// // ํ† ํฐ์ด ์กด์žฌํ•  ๊ฒฝ์šฐ์—๋งŒ GET ์š”์ฒญ ์ˆ˜ํ–‰
// const getFetch = async () => {
// try {
// const result = await axios.get(
// "https://port-0-backend-book-pharmacy-umnqdut2blqqhv7sd.sel5.cloudtype.app/hello",
// {
// headers: {
// // Authorization: `Bearer ${accessToken}`, // 'Bearer ' ์ ‘๋‘์–ด ์ถ”๊ฐ€ํ•˜์—ฌ ์•ก์„ธ์Šค ํ† ํฐ ์„ค์ •
// Authorization: token,
// },
// withCredentials: true, // ์ฟ ํ‚ค๋ฅผ ์ด์šฉํ•œ ์ธ์ฆ
// }
// );
// console.log(result);
// } catch(error) {
// console.error("๋กœ๊ทธ์ธ ์š”์ฒญ ์‹คํŒจ", error);
// }
// };
// getFetch();
// }
// }, []);

// ๋‚˜์ค‘์— ์ƒํƒœ๊ด€๋ฆฌ ์‚ฌ์šฉํ•ด์„œ ๋กœ๊ทธ์ธ ๊ด€๋ฆฌํ•˜๋„๋ก ํ•˜๊ธฐ
// refresh์— ๋Œ€ํ•œ post ์š”์ฒญ api ์ถ”๊ฐ€ํ•ด์•ผํ• ๊ฑฐ๊ฐ™์Œ
useEffect(() => {
Expand All @@ -115,21 +70,21 @@ export default function Login() {

const loginData = { username: id, password: pwd };

const postLogin = async () => {
const postLogin = () => {
// console.log('์•„์ด๋””:', id, '๋น„๋ฒˆ:', pwd);
setUserId(id);
setUserPwd(pwd);
if (id.length > 0 && pwd.length > 0) {
axios
.post('https://api.bookpharmacy.store/login', loginData, {
api
.post('/login', loginData, {
withCredentials: true,
})
.then((res) => {
// console.log(res);
localStorage.setItem('id', id);
localStorage.setItem('password', pwd);

// window.location.replace('/main');
window.location.replace('/main');
})
.catch((err) => {
console.log(err);
Expand Down
5 changes: 5 additions & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import axios from 'axios';

const api = axios.create({ baseURL: process.env.REACT_APP_API_URL });

export default api;

0 comments on commit f6dc624

Please sign in to comment.