diff --git a/packages/ra-ui-materialui/src/auth/Login.tsx b/packages/ra-ui-materialui/src/auth/Login.tsx index 07d009f26d8..fec65732c12 100644 --- a/packages/ra-ui-materialui/src/auth/Login.tsx +++ b/packages/ra-ui-materialui/src/auth/Login.tsx @@ -22,6 +22,52 @@ import { createMuiTheme } from '../layout'; import DefaultNotification from '../layout/Notification'; import DefaultLoginForm from './LoginForm'; +/** + * A standalone login page, to serve as authentication gate to the admin + * + * Expects the user to enter a login and a password, which will be checked + * by the `authProvider.login()` method. Redirects to the root page (/) + * upon success, otherwise displays an authentication error message. + * + * Copy and adapt this component to implement your own login logic + * (e.g. to authenticate via email or facebook or anything else). + * + * @example + * import MyLoginPage from './MyLoginPage'; + * const App = () => ( + * + * ... + * + * ); + */ +const Login: React.FunctionComponent = props => { + const { theme, ...rest } = props; + const muiTheme = useMemo(() => createMuiTheme(theme), [theme]); + + return ( + + + + ); +}; + +Login.propTypes = { + backgroundImage: PropTypes.string, + children: PropTypes.node, + classes: PropTypes.object, + className: PropTypes.string, + theme: PropTypes.object, + staticContext: PropTypes.object, +}; + +Login.defaultProps = { + theme: defaultTheme, + children: , + notification: DefaultNotification, +}; + +export default Login; + export interface LoginProps extends Omit, 'title'> { backgroundImage?: string; @@ -64,27 +110,8 @@ const useStyles = makeStyles( { name: 'RaLogin' } ); -/** - * A standalone login page, to serve as authentication gate to the admin - * - * Expects the user to enter a login and a password, which will be checked - * by the `authProvider.login()` method. Redirects to the root page (/) - * upon success, otherwise displays an authentication error message. - * - * Copy and adapt this component to implement your own login logic - * (e.g. to authenticate via email or facebook or anything else). - * - * @example - * import MyLoginPage from './MyLoginPage'; - * const App = () => ( - * - * ... - * - * ); - */ -const Login: React.FunctionComponent = props => { +const LoginView: React.FunctionComponent> = props => { const { - theme, title, classes: classesOverride, className, @@ -95,9 +122,8 @@ const Login: React.FunctionComponent = props => { ...rest } = props; const containerRef = useRef(); + const classes = useStyles(props); - const muiTheme = useMemo(() => createMuiTheme(theme), [theme]); - let backgroundImageLoaded = false; const checkAuth = useCheckAuth(); const history = useHistory(); useEffect(() => { @@ -111,6 +137,8 @@ const Login: React.FunctionComponent = props => { }); }, [checkAuth, history]); + let backgroundImageLoaded = false; + const updateBackgroundImage = () => { if (!backgroundImageLoaded && containerRef.current) { containerRef.current.style.backgroundImage = `url(${backgroundImage})`; @@ -134,39 +162,20 @@ const Login: React.FunctionComponent = props => { }); return ( - -
- -
- - - -
- {children} -
- {notification ? createElement(notification) : null} -
-
+
+ +
+ + + +
+ {children} +
+ {notification ? createElement(notification) : null} +
); }; - -Login.propTypes = { - backgroundImage: PropTypes.string, - children: PropTypes.node, - classes: PropTypes.object, - className: PropTypes.string, - theme: PropTypes.object, - staticContext: PropTypes.object, -}; - -Login.defaultProps = { - theme: defaultTheme, - children: , - notification: DefaultNotification, -}; - -export default Login;