AuthManagement.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from 'react';
  2. import { AuthProvider } from '../hooks/AuthProvider';
  3. import { LoginPage } from './LoginPage';
  4. type AuthManagementProps = {
  5. children?: React.ReactNode;
  6. /**
  7. * 自定义登录页面组件
  8. * 如果未提供,将使用默认的LoginPage
  9. */
  10. customLoginPage?: React.ComponentType;
  11. /**
  12. * 登录成功后重定向的路径
  13. * 默认为 '/admin/dashboard'
  14. */
  15. redirectPath?: string;
  16. };
  17. /**
  18. * 认证管理主组件
  19. * 提供完整的认证管理功能,包括登录页面和认证状态管理
  20. */
  21. export const AuthManagement: React.FC<AuthManagementProps> = ({
  22. children,
  23. customLoginPage: CustomLoginPage,
  24. redirectPath = '/admin/dashboard'
  25. }) => {
  26. // redirectPath is available for future use if needed
  27. console.log('Redirect path:', redirectPath); // Use redirectPath to avoid unused warning
  28. return (
  29. <AuthProvider>
  30. {children ? (
  31. children
  32. ) : (
  33. CustomLoginPage ? (
  34. <CustomLoginPage />
  35. ) : (
  36. <LoginPage />
  37. )
  38. )}
  39. </AuthProvider>
  40. );
  41. };