Skip to content

Commit

Permalink
Feat: Homepage auth 권한 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hhbb0081 committed Mar 8, 2024
1 parent 2bd6974 commit 4cc94e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ function App() {

//false : 로그인 한 유저 못들어감
const NewLoginPage = Auth(LoginPage, false); // 로그인 페이지

//true : 로그인 한 유저 들어감
const NewHomePage = Auth(HomePage, true); // 홈페이지
const NewAuthentication = Auth(AuthenticationPage, true, 1);
// const NewHomePage = Auth(HomePage, true, 2);
const NewOrderHistory = Auth(OrderHistory, true, 2);
const NewOrderDetail = Auth(OrderDetail, true, 2);
const NewMyprofilePage = Auth(MyprofilePage, true, 2);
Expand Down Expand Up @@ -129,7 +129,7 @@ function App() {
{/* 로그인 하지 않아도 볼 수 있는 페이지 */}
<Route path="/splash" element={<Splash />} />
{/* 메인페이지 */}
<Route path="/" element={<HomePage />} />
<Route path="/" element={<NewHomePage />} />
{/* 없는 경로로 갈 경우 메인페이지로 강제 이동 */}
<Route path="/*" element={<Navigate to="/"></Navigate>}></Route>
{/* 카페검색*/}
Expand Down
11 changes: 5 additions & 6 deletions src/hoc/auth.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { message } from "antd";
import React, { useEffect } from "react";
import { useCookies } from "react-cookie";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import { useSetRecoilState } from "recoil";
import { isAuthenticatedState } from "../Atom/status";
import commonApis from "../utils/commonApis";

function Auth(SpecificComponent, option, adminRoute = null) {
function AuthenticationCheck(props) {
const navigate = useNavigate();
const location = useLocation();
const [cookies, , removeCookie] = useCookies(["accessToken"]);
const setIsAuth = useSetRecoilState(isAuthenticatedState)
const token = localStorage.getItem("accessToken");

useEffect(() => {
function fetchAuth() {
commonApis.get("/auth", {
// headers: {
// Authorization: `Bearer ${token.accessToken}`
// },
withCredentials: true
}).then((response) => {
console.log(response);
Expand All @@ -37,7 +35,7 @@ function Auth(SpecificComponent, option, adminRoute = null) {
if (!auth) {
// 로그인 안 되어 있는 경우
setIsAuth(false);
if(option){
if(option && location.pathname !== '/'){
navigate('/login');
return;
}
Expand All @@ -57,9 +55,10 @@ function Auth(SpecificComponent, option, adminRoute = null) {
return;
} else if (role === 'USER'){
// 번호인증 한 유저
if(adminRoute !== 2){
if(adminRoute === 1){
navigate('/');
}
return;
}
}}).catch((error) => {
console.log(error);
Expand Down

0 comments on commit 4cc94e3

Please sign in to comment.