Skip to content

Commit

Permalink
Feat: auth adminRoute 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hhbb0081 committed Mar 8, 2024
1 parent 3182b80 commit 399fd70
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
27 changes: 14 additions & 13 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ function App() {
const NewLoginPage = Auth(LoginPage, false); // 로그인 페이지

//true : 로그인 한 유저 들어감
const NewHomePage = Auth(HomePage, true);
const NewOrderHistory = Auth(OrderHistory, true);
const NewOrderDetail = Auth(OrderDetail, true);
const NewMyprofilePage = Auth(MyprofilePage, 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);

const NewOrderProcessPage = Auth(OrderProcessPage, true);
const NewMembershipPage = Auth(MembershipPage, true);
const NewCouponPage = Auth(CouponPage, true);
const NewCartPage = Auth(CartPage, true);
const NewPaymentPage = Auth(PaymentPage, true);
const NewPaymentLoadingPage = Auth(PaymentLoadingPage, true);
const NewPaymentFailPage = Auth(PaymentFailPage, true);
const NewOrderProcessPage = Auth(OrderProcessPage, true, 2);
const NewMembershipPage = Auth(MembershipPage, true, 2);
const NewCouponPage = Auth(CouponPage, true, 2);
const NewCartPage = Auth(CartPage, true, 2);
const NewPaymentPage = Auth(PaymentPage, true, 2);
const NewPaymentLoadingPage = Auth(PaymentLoadingPage, true, 2);
const NewPaymentFailPage = Auth(PaymentFailPage, true, 2);
// const NewPackagingStatusPage = Auth(PackagingStatusPage, true);

const minute = 1000 * 60 * 60 * 24; // 24시간
Expand Down Expand Up @@ -128,15 +129,15 @@ function App() {
{/* 로그인 하지 않아도 볼 수 있는 페이지 */}
<Route path="/splash" element={<Splash />} />
{/* 메인페이지 */}
<Route path="/" element={<NewHomePage />} />
<Route path="/" element={<HomePage />} />
{/* 없는 경로로 갈 경우 메인페이지로 강제 이동 */}
<Route path="/*" element={<Navigate to="/"></Navigate>}></Route>
{/* 카페검색*/}
<Route path="/search" element={<StoreSearchPage />} />
{/* 로그인*/}
<Route path="/login" element={<NewLoginPage />} />
{/* 번호인증 페이지 */}
<Route path="/authentication" element={<AuthenticationPage/>} />
<Route path="/authentication" element={<NewAuthentication/>} />
{/* 쿠폰 및 포인트 faq페이지*/}
<Route path="/faq" element={<FrequentlyAskedQuestionPage />} />
{/* 마이페이지-약관정책 페이지 */}
Expand Down
22 changes: 15 additions & 7 deletions src/hoc/auth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSetRecoilState } from "recoil";
import { isAuthenticatedState } from "../Atom/status";
import commonApis from "../utils/commonApis";

function Auth(SpecificComponent, option) {
function Auth(SpecificComponent, option, adminRoute = null) {
function AuthenticationCheck(props) {
const navigate = useNavigate();
const [cookies, , removeCookie] = useCookies(["accessToken"]);
Expand Down Expand Up @@ -44,15 +44,23 @@ function Auth(SpecificComponent, option) {
}
else {
// 로그인이 된 경우
if(role === 'GUEST'){
// 번호인증 안 한 유저
navigate('/authentication');
return;
}
if(!option){
// 로그인하면 갈 수 없는 페이지
navigate('/');
return;
}
if(role === 'GUEST'){
// 번호인증 안 한 유저
if(adminRoute !== 1){
navigate('/authentication');
}
return;
} else if (role === 'USER'){
// 번호인증 한 유저
if(adminRoute !== 2){
navigate('/');
}
}
}}).catch((error) => {
console.log(error);
if (
Expand All @@ -62,7 +70,7 @@ function Auth(SpecificComponent, option) {
) {
// 클라이언트 오류 발생 (400번대 오류)
// 로그인 페이지로 되돌아가는 조건문 추가
// navigate('/login');
navigate('/login');
} else {
// 서버 오류 또는 네트워크 오류 등의 다른 오류 처리
}
Expand Down

0 comments on commit 399fd70

Please sign in to comment.