mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
fixed login
This commit is contained in:
@@ -14,7 +14,7 @@ import Settings from './pages/Settings/Settings';
|
||||
import Help from './pages/Help/Help';
|
||||
import Setup from './pages/Setup/Setup';
|
||||
|
||||
// Protected Route Component direkt in App.tsx
|
||||
// Protected Route Component
|
||||
const ProtectedRoute: React.FC<{ children: React.ReactNode; roles?: string[] }> = ({
|
||||
children,
|
||||
roles = ['admin', 'instandhalter', 'user']
|
||||
@@ -47,6 +47,89 @@ const ProtectedRoute: React.FC<{ children: React.ReactNode; roles?: string[] }>
|
||||
return <Layout>{children}</Layout>;
|
||||
};
|
||||
|
||||
// SetupWrapper Component
|
||||
const SetupWrapper: React.FC = () => {
|
||||
return (
|
||||
<Router>
|
||||
<Setup />
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
||||
// LoginWrapper Component
|
||||
const LoginWrapper: React.FC = () => {
|
||||
return (
|
||||
<Router>
|
||||
<Login />
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
||||
// Main App Content
|
||||
const AppContent: React.FC = () => {
|
||||
const { loading, needsSetup, user } = useAuth();
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '40px' }}>
|
||||
<div>⏳ Lade Anwendung...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
console.log('AppContent - needsSetup:', needsSetup, 'user:', user);
|
||||
|
||||
// Wenn Setup benötigt wird → Setup zeigen (mit Router)
|
||||
if (needsSetup) {
|
||||
return <SetupWrapper />;
|
||||
}
|
||||
|
||||
// Wenn kein User eingeloggt ist → Login zeigen (mit Router)
|
||||
if (!user) {
|
||||
return <LoginWrapper />;
|
||||
}
|
||||
|
||||
// Wenn User eingeloggt ist → Geschützte Routen zeigen
|
||||
return (
|
||||
<Router>
|
||||
<NotificationContainer />
|
||||
<Routes>
|
||||
<Route path="/" element={
|
||||
<ProtectedRoute>
|
||||
<Dashboard />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/shift-plans" element={
|
||||
<ProtectedRoute>
|
||||
<ShiftPlanList />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/shift-plans/new" element={
|
||||
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
||||
<ShiftPlanCreate />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/employees" element={
|
||||
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
||||
<EmployeeManagement />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/settings" element={
|
||||
<ProtectedRoute roles={['admin']}>
|
||||
<Settings />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/help" element={
|
||||
<ProtectedRoute>
|
||||
<Help />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/login" element={<Login />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<NotificationProvider>
|
||||
@@ -57,61 +140,4 @@ function App() {
|
||||
);
|
||||
}
|
||||
|
||||
function AppContent() {
|
||||
const { loading, needsSetup } = useAuth();
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '40px' }}>
|
||||
<div>⏳ Lade Anwendung...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Router>
|
||||
<NotificationContainer />
|
||||
<Routes>
|
||||
{needsSetup ? (
|
||||
<Route path="*" element={<Setup />} />
|
||||
) : (
|
||||
<>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/" element={
|
||||
<ProtectedRoute>
|
||||
<Dashboard />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/shift-plans" element={
|
||||
<ProtectedRoute>
|
||||
<ShiftPlanList />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/shift-plans/new" element={
|
||||
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
||||
<ShiftPlanCreate />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/employees" element={
|
||||
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
||||
<EmployeeManagement />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/settings" element={
|
||||
<ProtectedRoute roles={['admin']}>
|
||||
<Settings />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/help" element={
|
||||
<ProtectedRoute>
|
||||
<Help />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
</>
|
||||
)}
|
||||
</Routes>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
Reference in New Issue
Block a user