put nexgraph auth and data access behind a url based feature flag

main
Christopher Maujean 2 months ago
parent 024ad59d1a
commit 30412ff25f
  1. 26
      src/App.tsx
  2. 1
      src/components/layout/DashboardLayout.tsx
  3. 8
      src/pages/AccountPage.tsx
  4. 11
      src/utils/featureFlags.ts
  5. 19
      test-feature-flag.md

@ -3,7 +3,6 @@ import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline'; import CssBaseline from '@mui/material/CssBaseline';
import { OnboardingProvider } from '@/contexts/OnboardingContext'; import { OnboardingProvider } from '@/contexts/OnboardingContext';
import { BrowserNGLdoProvider, useNextGraphAuth } from '@/lib/nextgraph'; import { BrowserNGLdoProvider, useNextGraphAuth } from '@/lib/nextgraph';
import type { NextGraphAuth } from '@/types/nextgraph';
import DashboardLayout from '@/components/layout/DashboardLayout'; import DashboardLayout from '@/components/layout/DashboardLayout';
import SocialContractPage from '@/pages/SocialContractPage'; import SocialContractPage from '@/pages/SocialContractPage';
import GroupJoinPage from '@/pages/GroupJoinPage'; import GroupJoinPage from '@/pages/GroupJoinPage';
@ -22,10 +21,11 @@ import AccountPage from '@/pages/AccountPage';
import NotificationsPage from '@/pages/NotificationsPage'; import NotificationsPage from '@/pages/NotificationsPage';
import { createAppTheme } from '@/theme/theme'; import { createAppTheme } from '@/theme/theme';
import { Container, Box, Typography, Button } from '@mui/material'; import { Container, Box, Typography, Button } from '@mui/material';
import { isNextGraphEnabled } from '@/utils/featureFlags';
const theme = createAppTheme('light'); const theme = createAppTheme('light');
const AppContent = () => { const NextGraphAppContent = () => {
const nextGraphAuth = useNextGraphAuth(); const nextGraphAuth = useNextGraphAuth();
const { session, login, logout } = nextGraphAuth || {}; const { session, login, logout } = nextGraphAuth || {};
@ -86,7 +86,14 @@ const AppContent = () => {
); );
} }
return ( return <AppRoutes />;
};
const MockAppContent = () => {
return <AppRoutes />;
};
const AppRoutes = () => (
<OnboardingProvider> <OnboardingProvider>
<Router> <Router>
<Routes> <Routes>
@ -117,6 +124,15 @@ const AppContent = () => {
</Router> </Router>
</OnboardingProvider> </OnboardingProvider>
); );
const AppContent = () => {
const useNextGraph = isNextGraphEnabled();
if (useNextGraph) {
return <NextGraphAppContent />;
}
return <MockAppContent />;
}; };
function App() { function App() {
@ -124,9 +140,13 @@ function App() {
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<CssBaseline /> <CssBaseline />
<Container maxWidth="lg"> <Container maxWidth="lg">
{isNextGraphEnabled() ? (
<BrowserNGLdoProvider> <BrowserNGLdoProvider>
<AppContent /> <AppContent />
</BrowserNGLdoProvider> </BrowserNGLdoProvider>
) : (
<AppContent />
)}
</Container> </Container>
</ThemeProvider> </ThemeProvider>
); );

@ -1,7 +1,6 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import { useLocation, useNavigate } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
import { useNextGraphAuth } from '@/lib/nextgraph';
import { import {
Box, Box,
Drawer, Drawer,

@ -1,6 +1,7 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { useSearchParams } from 'react-router-dom'; import { useSearchParams } from 'react-router-dom';
import { useNextGraphAuth } from '@/lib/nextgraph'; import { useNextGraphAuth } from '@/lib/nextgraph';
import { isNextGraphEnabled } from '@/utils/featureFlags';
import { import {
Typography, Typography,
Box, Box,
@ -61,6 +62,7 @@ const AccountPage = () => {
const theme = useTheme(); const theme = useTheme();
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const nextGraphAuth = useNextGraphAuth(); const nextGraphAuth = useNextGraphAuth();
const useNextGraph = isNextGraphEnabled();
// Initialize tab from URL parameter // Initialize tab from URL parameter
const initialTab = parseInt(searchParams.get('tab') || '0', 10); const initialTab = parseInt(searchParams.get('tab') || '0', 10);
@ -596,7 +598,8 @@ const AccountPage = () => {
</TabPanel> </TabPanel>
</Box> </Box>
{/* Logout Button - Always visible at bottom */} {/* Logout Button - Only show in NextGraph mode */}
{useNextGraph && (
<Box sx={{ mt: 3, mb: 2, textAlign: 'center' }}> <Box sx={{ mt: 3, mb: 2, textAlign: 'center' }}>
<Button <Button
variant="outlined" variant="outlined"
@ -606,7 +609,7 @@ const AccountPage = () => {
console.log('NextGraph Auth object:', nextGraphAuth); console.log('NextGraph Auth object:', nextGraphAuth);
console.log('Available methods:', nextGraphAuth ? Object.keys(nextGraphAuth) : 'none'); console.log('Available methods:', nextGraphAuth ? Object.keys(nextGraphAuth) : 'none');
if (nextGraphAuth?.logout && typeof nextGraphAuth.logout === 'function') { if (useNextGraph && nextGraphAuth?.logout && typeof nextGraphAuth.logout === 'function') {
console.log('Calling logout...'); console.log('Calling logout...');
await nextGraphAuth.logout(); await nextGraphAuth.logout();
} else { } else {
@ -628,6 +631,7 @@ const AccountPage = () => {
Logout Logout
</Button> </Button>
</Box> </Box>
)}
{/* rCard Management Dialog */} {/* rCard Management Dialog */}
<RCardManagement <RCardManagement

@ -0,0 +1,11 @@
export const getFeatureFlags = () => {
const urlParams = new URLSearchParams(window.location.search);
return {
useNextGraph: urlParams.get('nextgraph') === 'true'
};
};
export const isNextGraphEnabled = (): boolean => {
return getFeatureFlags().useNextGraph;
};

@ -0,0 +1,19 @@
# Feature Flag Testing
## Default Mode (Mock Data)
- URL: `http://localhost:5173/`
- Expected: App loads directly without NextGraph login
- Features: Uses mock JSON data from `/public/contacts.json`
- No logout button shown in Account page
## NextGraph Mode
- URL: `http://localhost:5173/?nextgraph=true`
- Expected: Shows NextGraph login screen initially
- Features: Uses LDO and NextGraph auth system
- Logout button shown in Account page
## Implementation Details
- Feature flag detected via URL parameter `nextgraph=true`
- Utility: `/src/utils/featureFlags.ts`
- Main conditional logic in `/src/App.tsx`
- Account page conditionally shows logout in NextGraph mode only
Loading…
Cancel
Save