Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"jsonwebtoken": "^9.0.2",
"lottie-react": "^2.4.0",
"lucide-react": "^0.474.0",
"mohamed-mujtaba-coffee-shop": "file:",
"mongodb": "^6.18.0",
"mongoose": "^8.0.3",
"openai": "^4.78.0",
Expand Down
91 changes: 17 additions & 74 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import ExpertBaristas from './Pages/ExpertBaristas';
import CozyAmbiance from './Pages/CozyAmbiance';
import Feedback from './Pages/Feedback';
import Favorites from './Pages/favorites';
import Wishlist from './Pages/wishlist';
import Reviews from './componets/Reviews';
import AnimatedCursor from 'react-animated-cursor';

import Chatbot from "./componets/Chatbot";

// Styled Containers
Expand All @@ -54,14 +54,11 @@ const ContentContainer = styled.div`
flex: 1;
`;

// ✅ Enhanced Protected Profile Route with Google Auth
const SafeProfileRoute = () => {
const { isAuthenticated, user, loading } = useSelector((state) => state.auth);

// Check both new auth system and legacy localStorage
const legacyUserData = localStorage.getItem('user');
const legacyUser = legacyUserData ? JSON.parse(legacyUserData) : null;

if (loading) {
return (
<div className="flex justify-center items-center min-h-screen">
Expand All @@ -70,11 +67,9 @@ const SafeProfileRoute = () => {
);
}

// Allow access if authenticated through Google Auth OR legacy system
return (isAuthenticated && user) || legacyUser ? <Profile /> : <Navigate to="/login" replace />;
};

// ✅ Protected Route Component for other protected pages
const ProtectedRoute = ({ children }) => {
const { isAuthenticated, user, loading } = useSelector((state) => state.auth);
const legacyUserData = localStorage.getItem('user');
Expand All @@ -91,10 +86,9 @@ const ProtectedRoute = ({ children }) => {
return (isAuthenticated && user) || legacyUser ? children : <Navigate to="/login" replace />;
};

// ✅ Main App Content Component
const AppContent = () => {
const dispatch = useDispatch();
const { token, user } = useSelector((state) => state.auth);
const { token, user } = useSelector((state) => state.auth);

useEffect(() => {
if (token && !user) {
Expand All @@ -105,32 +99,10 @@ const AppContent = () => {
return (
<AppContainer>
<Navbar />

<AnimatedCursor
innerSize={20}
outerSize={20}
color="104, 225, 239"
outerAlpha={0.2}
innerScale={0.7}
outerScale={5}
/>

<ToastContainer
position="top-right"
autoClose={3000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="light"
/>

<AnimatedCursor innerSize={20} outerSize={20} color="104, 225, 239" outerAlpha={0.2} innerScale={0.7} outerScale={5} />
<ToastContainer position="top-right" autoClose={3000} theme="light" />
<ContentContainer>
<Routes>
{/* Public Routes */}
<Route path="/" element={<Home />} />
<Route path="/home" element={<Home />} />
<Route path="/login" element={<Login />} />
Expand All @@ -152,58 +124,29 @@ const AppContent = () => {
<Route path="/premiumbeans" element={<PremiumBeans />} />
<Route path="/expertbaristas" element={<ExpertBaristas />} />
<Route path="/cozyambiance" element={<CozyAmbiance />} />

{/* Protected Routes */}
<Route path="/profile" element={<SafeProfileRoute />} />
<Route
path="/cart"
element={
<ProtectedRoute>
<Cart />
</ProtectedRoute>
}
/>
<Route
path="/checkout"
element={
<ProtectedRoute>
<Checkout />
</ProtectedRoute>
}
/>
<Route
path="/favorites"
element={
<ProtectedRoute>
<Favorites />
</ProtectedRoute>
}
/>
<Route
path="/feedback"
element={
<ProtectedRoute>
<Feedback />
</ProtectedRoute>
}
/>
<Route path="/favorites" element={<ProtectedRoute><Favorites /></ProtectedRoute>} />
<Route path="/feedback" element={<ProtectedRoute><Feedback /></ProtectedRoute>} />
<Route path="/cart" element={<ProtectedRoute><Cart /></ProtectedRoute>} />
<Route path="/checkout" element={<ProtectedRoute><Checkout /></ProtectedRoute>} />
<Route path="/wishlist" element={<Wishlist />} />
</Routes>
</ContentContainer>

<Reviews />

{/* Add Chatbot so it floats on every page */}
<Chatbot />

<Footer />
</AppContainer>
);
};

// ✅ Main App Component with Google OAuth Provider
function App() {
// Handle Google OAuth client ID for different environments
const googleClientId = process.env.REACT_APP_GOOGLE_CLIENT_ID ||
process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID ||
"placeholder_client_id";

return (
<GoogleOAuthProvider clientId={process.env.REACT_APP_GOOGLE_CLIENT_ID}>
<GoogleOAuthProvider clientId={googleClientId}>
<Provider store={store}>
<Router>
<ScrollToTop />
Expand All @@ -214,4 +157,4 @@ function App() {
);
}

export default App;
export default App;
Loading