--- layout: default title: "useLogin" --- # `useLogin` This hook returns a callback allowing to call `authProvider.login()`. It's used in Login forms. ## Usage Here is how to build a custom Login page based on email rather than username: ```jsx // in src/MyLoginPage.js import * as React from 'react'; import { useState } from 'react'; import { useLogin, useNotify, Notification } from 'react-admin'; const MyLoginPage = ({ theme }) => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const login = useLogin(); const notify = useNotify(); const handleSubmit = e => { e.preventDefault(); // will call authProvider.login({ email, password }) login({ email, password }).catch(() => notify('Invalid email or password') ); }; return (
setEmail(e.target.value)} /> setPassword(e.target.value)} />
); }; export default MyLoginPage; ``` Then pass the custom Login form to ``, as follows: ```jsx // in src/App.js import * as React from "react"; import { Admin } from 'react-admin'; import MyLoginPage from './MyLoginPage'; const App = () => ( ... ); ```