Skip to main content
Version: 4.xx.xxSwizzle ReadySource Code

<AuthPage>

<AuthPage> component from refine for Material UI contains authentication pages that can be used to login, register, forgot password, and update password.

Before using <AuthPage> component you need to add authProvider that will be used to handle authentication.

Swizzle

You can swizzle this component to customize it with the refine CLI

Usage

<AuthPage> component can be used like this:

http://localhost:3000
import { Refine, Authenticated } from "@refinedev/core";
import dataProvider from "@refinedev/simple-rest";
import { AuthPage, Layout } from "@refinedev/mui";
import routerProvider, {
CatchAllNavigate,
NavigateToResource,
} from "@refinedev/react-router-v6";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { authProvider } from "./authProvider";
import { DashboardPage } from "./pages/dashboard";

const App = () => {
return (
<BrowserRouter>
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
routerProvider={routerProvider}
authProvider={authProvider}
>
<Routes>
<Route
element={
<Authenticated
fallback={<CatchAllNavigate to="/login" />}
>
<Layout>
<Outlet />
</Layout>
</Authenticated>
}
>
<Route index element={<DashboardPage />} />
</Route>
<Route
element={
<Authenticated fallback={<Outlet />}>
<NavigateToResource />
</Authenticated>
}
>
<Route
path="/login"
element={<AuthPage type="login" />}
/>
</Route>
</Routes>
</Refine>
</BrowserRouter>
);
};

Types

<AuthPage> component has the following types:

Login

login will be used as the default type of the <AuthPage> component. The login page will be used to log in to the system.

http://localhost:3000/login
import { Refine, Authenticated } from "@refinedev/core";
import dataProvider from "@refinedev/simple-rest";
import routerProvider, {
CatchAllNavigate,
NavigateToResource,
} from "@refinedev/react-router-v6";

import { AuthPage, Layout } from "@refinedev/mui";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { authProvider } from "./authProvider";

import { DashboardPage } from "pages/dashboard";

const App = () => {
return (
<BrowserRouter>
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
routerProvider={routerProvider}
authProvider={authProvider}
>
<Routes>
<Route
element={
<Authenticated
fallback={<CatchAllNavigate to="/login" />}
>
<Layout>
<Outlet />
</Layout>
</Authenticated>
}
>
<Route index element={<DashboardPage />} />
</Route>
<Route
element={
<Authenticated fallback={<Outlet />}>
<NavigateToResource />
</Authenticated>
}
>
<Route path="/login" element={<AuthPage />} />
</Route>
</Routes>
</Refine>
</BrowserRouter>
);
};

After form submission, the login method of the authProvider will be called with the form values.

src/authProvider.ts
import { AuthBindings } from "@refinedev/core";

const authProvider: AuthBindings = {
// --
login: async ({ email, password, remember, providerName }) => {
// You can handle the login process according to your needs.

// If the process is successful.
return {
success: true,
};

return {
success: false,
error: {
name: "Login Error",
message: "Invalid email or password",
},
};
},
// --
};

Register

The register page will be used to register new users. You can use the following props for the <AuthPage> component when the type is "register":

http://localhost:3000/register
import { Refine, Authenticated } from "@refinedev/core";
import dataProvider from "@refinedev/simple-rest";
import routerProvider, {
CatchAllNavigate,
NavigateToResource,
} from "@refinedev/react-router-v6";

import { AuthPage, Layout } from "@refinedev/mui";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { authProvider } from "./authProvider";

import { DashboardPage } from "pages/dashboard";

const App = () => {
return (
<BrowserRouter>
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
routerProvider={routerProvider}
authProvider={authProvider}
>
<Routes>
<Route
element={
<Authenticated
fallback={<CatchAllNavigate to="/login" />}
>
<Layout>
<Outlet />
</Layout>
</Authenticated>
}
>
<Route index element={<DashboardPage />} />
</Route>
<Route
element={
<Authenticated fallback={<Outlet />}>
<NavigateToResource />
</Authenticated>
}
>
<Route path="/login" element={<AuthPage />} />
<Route
path="/register"
element={<AuthPage type="register" />}
/>
</Route>
</Routes>
</Refine>
</BrowserRouter>
);
};

After form submission, the register method of the authProvider will be called with the form values.

src/authProvider.ts
import { AuthBindings } from "@refinedev/core";

const authProvider: AuthBindings = {
// --
register: async ({ email, password, providerName }) => {
// You can handle the register process according to your needs.

// If the process is successful.
return {
success: true,
};

return {
success: false,
error: {
name: "Register Error",
message: "Invalid email or password",
},
};
},
// --
};

ForgotPassword

The forgotPassword type is a page that allows users to reset their passwords. You can use this page to reset your password.

http://localhost:3000/forgot-password
import { Refine, Authenticated } from "@refinedev/core";
import dataProvider from "@refinedev/simple-rest";
import routerProvider, {
CatchAllNavigate,
NavigateToResource,
} from "@refinedev/react-router-v6";

import { AuthPage, Layout } from "@refinedev/mui";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { authProvider } from "./authProvider";

import { DashboardPage } from "pages/dashboard";

const App = () => {
return (
<BrowserRouter>
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
routerProvider={routerProvider}
authProvider={authProvider}
>
<Routes>
<Route
element={
<Authenticated
fallback={<CatchAllNavigate to="/login" />}
>
<Layout>
<Outlet />
</Layout>
</Authenticated>
}
>
<Route index element={<DashboardPage />} />
</Route>
<Route
element={
<Authenticated fallback={<Outlet />}>
<NavigateToResource />
</Authenticated>
}
>
<Route path="/login" element={<AuthPage />} />
<Route
path="/register"
element={<AuthPage type="register" />}
/>
<Route
path="/forgot-password"
element={<AuthPage type="forgotPassword" />}
/>
</Route>
</Routes>
</Refine>
</BrowserRouter>
);
};

After form submission, the forgotPassword method of the authProvider will be called with the form values.

src/authProvider.ts
import { AuthBindings } from "@refinedev/core";

const authProvider: AuthBindings = {
// --
forgotPassword: async ({ email }) => {
// You can handle the reset password process according to your needs.

// If process is successful.
return {
success: true,
};

return {
success: false,
error: {
name: "Forgot Password Error",
message: "Invalid email or password",
},
};
},
// --
};

UpdatePassword

The updatePassword type is the page used to update the password of the user.

http://localhost:3000/update-password
import { Refine, Authenticated } from "@refinedev/core";
import dataProvider from "@refinedev/simple-rest";
import routerProvider, {
CatchAllNavigate,
NavigateToResource,
} from "@refinedev/react-router-v6";

import { AuthPage, Layout } from "@refinedev/mui";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { authProvider } from "./authProvider";

import { DashboardPage } from "pages/dashboard";

const App = () => {
return (
<BrowserRouter>
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
routerProvider={routerProvider}
authProvider={authProvider}
>
<Routes>
<Route
element={
<Authenticated
fallback={<CatchAllNavigate to="/login" />}
>
<Layout>
<Outlet />
</Layout>
</Authenticated>
}
>
<Route index element={<DashboardPage />} />
</Route>
<Route
element={
<Authenticated fallback={<Outlet />}>
<NavigateToResource />
</Authenticated>
}
>
<Route path="/login" element={<AuthPage />} />
<Route
path="/register"
element={<AuthPage type="register" />}
/>
<Route
path="/forgot-password"
element={<AuthPage type="forgotPassword" />}
/>
<Route
path="/update-password"
element={<AuthPage type="updatePassword" />}
/>
</Route>
</Routes>
</Refine>
</BrowserRouter>
);
};

After form submission, the updatePassword method of the authProvider will be called with the form values.

src/authProvider.ts
import { AuthBindings } from "@refinedev/core";

const authProvider: AuthBindings = {
// --
updatePassword: async ({ password, confirmPassword }) => {
// You can handle the update password process according to your needs.

// If the process is successful.
return {
success: true,
};

return {
success: false,
error: {
name: "Update Password Error",
message: "Invalid email or password",
},
};
},
// --
};

Props

providers

info

providers property is only available for types login and register.

providers property defines the list of providers used to handle login authentication. providers accepts an array of Provider type. Check out the Interface section for more information.

const MyLoginPage = () => {
return (
<AuthPage
providers={[
{
name: "google",
icon: GoogleIcon,
label: "Sign in with Google",
},
{
name: "github",
icon: GithubIcon,
label: "Sign in with GitHub",
},
]}
/>
);
};

rememberMe

info

rememberMe property is only available for type login.

rememberMe property defines to render your own remember me component or you can pass false to don't render it.

const MyLoginPage = () => {
return (
<AuthPage
rememberMe={
<FormControlLabel
sx={{
span: {
fontSize: "12px",
color: "text.secondary",
},
}}
color="secondary"
control={<Checkbox size="small" id="rememberMe" />}
label="Remember me"
/>
}
/>
);
};
info

loginLink property is only available for types register and forgotPassword.

loginLink property defines the link to the login page and also you can give a node to render. The default value is "/login".

const MyRegisterPage = () => {
return (
<AuthPage
loginLink={
<span
style={{
border: "1px dashed cornflowerblue",
padding: 3,
}}
>
<Link to="/login">Login</Link>
</span>
}
/>
);
};
info

registerLink property is only available for type login.

registerLink property defines the link to the registration page and also you can give a node to render. The default value is "/register".

const MyLoginPage = () => {
return (
<AuthPage
registerLink={
<div
style={{
border: "1px dashed cornflowerblue",
marginTop: 5,
padding: 5,
}}
>
<Link to="/register">Register</Link>
</div>
}
/>
);
};
info

forgotPasswordLink property is only available for type login.

forgotPasswordLink property defines the link to the forgot password page and also you can give a node to render. The default value is "/forgot-password".

const MyLoginPage = () => {
return (
<AuthPage
forgotPasswordLink={
<div
style={{
border: "1px dashed cornflowerblue",
marginTop: 5,
padding: 5,
}}
>
<Link to="/register">Forgot Password</Link>
</div>
}
/>
);
};

wrapperProps

wrapperProps uses for passing props to the wrapper component. In the example below you can see that the background color is changed with wrapperProps

const MyLoginPage = () => {
return (
<AuthPage
wrapperProps={{
style: {
background: "#331049",
},
}}
/>
);
};

contentProps

contentProps uses for passing props to the content component which is the card component. In the example below you can see that the title, header, and content styles are changed with contentProps.

const MyLoginPage = () => {
return (
<AuthPage
contentProps={{
title: "Login",
headStyle: {
background: "cornflowerblue",
color: "white",
},
bodyStyle: {
background: "#673ab742",
},
}}
/>
);
};

formProps

formProps uses for passing props to the form component. In the example below you can see that the initialValues are changed with formProps and also the onSubmit function is changed.

const MyLoginPage = () => {
return (
<AuthPage
formProps={{
onSubmit: (formValues) => {
alert(JSON.stringify(formValues, null, 2));
},
defaultValues: {
email: "test@mail.com",
},
}}
/>
);
};

renderContent

renderContent uses to render the form content. You can use this property to render your own content or renderContent gives you default content you can use to add some extra elements to the content.

const MyLoginPage = () => {
return (
<AuthPage
contentProps={{
style: {
width: "400px",
},
}}
renderContent={(content: React.ReactNode) => {
return (
<div
style={{
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
}}
>
<h1 style={{ color: "white" }}>Extra Header</h1>
{content}
<h1 style={{ color: "white" }}>Extra Footer</h1>
</div>
);
}}
/>
);
};

API Reference

Properties

Interface

interface OAuthProvider {
name: string;
icon?: React.ReactNode;
label?: string;
}
import { UseFormProps } from "@refinedev/react-hook-form";

interface FormPropsType extends UseFormProps {
onSubmit?: (values: any) => void;
}