[개인 포트폴리오] [클라이밍 커뮤니티 SNS] 2. 코드 분석 <protected-route.js>
2024. 12. 20. 10:16ㆍ웹개발 포트폴리오
728x90
import React from "react";
import { Navigate } from 'react-router-dom';
import { useAuthState } from 'react-firebase-hooks/auth';
import { getAuth } from 'firebase/auth';
const auth = getAuth();
// Firebase Authentication 서비스의 인스턴스를 가져오는 코드
const ProtectedRoute = ({ children }) => {
const [user, loading] = useAuthState(auth);
if (loading) {
return <div>Loading...</div>;
}
if (!user) {
return <Navigate to="/login" replace />;
// replace : 뒤로 가기 버튼을 눌러 이전 페이지로 돌아가는 것을 방지
}
if (loading) {
return <div>Loading...</div>;
}
return <>{children}</>;
};
export default ProtectedRoute;
728x90
'웹개발 포트폴리오' 카테고리의 다른 글
[개인 포트폴리오] [클라이밍 커뮤니티 SNS] 2. 코드 분석 <create-account.js> (0) | 2024.12.20 |
---|---|
[개인 포트폴리오] [클라이밍 커뮤니티 SNS] 2. 코드 분석 <login.js> (0) | 2024.12.20 |
[개인 포트폴리오] [클라이밍 커뮤니티 SNS] 2. 코드 분석 <layout.js> (0) | 2024.12.20 |
[개인 포트폴리오] [클라이밍 커뮤니티 SNS] 2. 코드 분석 <App.js> (0) | 2024.12.20 |
[개인 포트폴리오] [클리이밍 커뮤니티 SNS] 1. 구상 및 완성 과정 (0) | 2024.12.19 |