Skip to main content
Version: 4.xx.xx
Swizzle Ready
Source Code

<AuthPage />

<AuthPage> component from Refine for Ant Design contains authentication pages that can be used for the login, register, forgot password, and update password actions.

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

Good to know:

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

Usage

The <AuthPage> component can be used like this:

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

import { ConfigProvider } from "antd";

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

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

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

Types

The <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.

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, ThemedLayoutV2, RefineThemes } from "@refinedev/antd";

import { ConfigProvider } from "antd";

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

import { authProvider } from "./authProvider";

import { DashboardPage } from "pages/dashboard";

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

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

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

const authProvider: AuthProvider = {
// --
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":

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, ThemedLayoutV2, RefineThemes } from "@refinedev/antd";

import { ConfigProvider } from "antd";

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

import { authProvider } from "./authProvider";

import { DashboardPage } from "pages/dashboard";

const App = () => {
return (
<BrowserRouter>
<ConfigProvider theme={RefineThemes.Blue}>
<Refine
dataProvider={dataProvider("https://api.fake-rest.refine.dev")}
routerProvider={routerProvider}
authProvider={authProvider}
>
<Routes>
<Route
element={
<Authenticated fallback={<CatchAllNavigate to="/login" />}>
<ThemedLayoutV2>
<Outlet />
</ThemedLayoutV2>
</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>
</ConfigProvider>
</BrowserRouter>
);
};

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

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

const authProvider: AuthProvider = {
// --
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.

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, ThemedLayoutV2, RefineThemes } from "@refinedev/antd";

import { ConfigProvider } from "antd";

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" />}>
<ThemedLayoutV2>
<Outlet />
</ThemedLayoutV2>
</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 { AuthProvider } from "@refinedev/core";

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

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

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

UpdatePassword

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

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, ThemedLayoutV2, RefineThemes } from "@refinedev/antd";

import { ConfigProvider } from "antd";

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" />}>
<ThemedLayoutV2>
<Outlet />
</ThemedLayoutV2>
</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 { AuthProvider } from "@refinedev/core";

const authProvider: AuthProvider = {
// --
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: "Login Error",
message: "Invalid email or password",
},
};
},
// --
};

Props

hideForm

When you set hideForm to true, the form will be hidden. You can use this property to show only providers.

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

providers

The providers property defines the list of providers used to handle login authentication. providers accepts an array of Provider type. This property is only available for types login and register.

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

For more information, refer to the Interface section

rememberMe

The rememberMe property defines to render your custom <RememberMe> component or you can pass false to don't render it. This property is only available for type login.

You have to wrap your custom <RememberMe> component with the Form.Item component from Ant Design and pass the name prop to it then you can access its value from the formProps onFinish function with formValues.

const MyLoginPage = () => {
return (
<AuthPage
type="login"
rememberMe={
<div
style={{
border: "1px dashed cornflowerblue",
padding: 3,
}}
>
<Form.Item name="remember" valuePropName="checked" noStyle>
<Checkbox>Custom remember me</Checkbox>
</Form.Item>
</div>
}
/>
);
};

The loginLink property defines the link to the login page and also you can give a node to render. The default value is "/login". This property is only available for type register and forgotPassword.

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

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

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

The forgotPasswordLink property defines the link to the forgot password page and also you can give a node to render. Its default value is "/forgot-password". This property is only available for type login.

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

wrapperProps

The wrapperProps is used 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
type="login"
wrapperProps={{
style: {
background: "#331049",
},
}}
/>
);
};

contentProps

The contentProps is used 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
type="login"
contentProps={{
title: "Login",
headStyle: {
background: "cornflowerblue",
color: "white",
},
bodyStyle: {
background: "#673ab742",
},
}}
/>
);
};

formProps

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

const MyLoginPage = () => {
return (
<AuthPage
type="login"
formProps={{
initialValues: {
email: "demo@refine.dev",
password: "demo",
},
onFinish: (formValues) => alert(JSON.stringify(formValues, null, 2)),
}}
/>
);
};

title

By default, AuthPage uses text with icon on top of page. You can use this property to change the default title.

  • Default text is: Refine Project
  • Default icon is: Refine Logo
import { AuthPage, ThemedTitle } from "@refinedev/antd";

const MyLoginPage = () => {
return <AuthPage type="login" title={<h1>My Title</h1>} />;
};

Or you can customize the title with the ThemedTitle component.

import { AuthPage } from "@refinedev/antd";

const MyLoginPage = () => {
return (
<AuthPage
type="login"
title={
<ThemedTitleV2
title="My Title"
icon={<img src="https://refine.dev/img/logo.png" />}
/>
}
/>
);
};

renderContent

renderContent is used to render the form content and the title. You can use this property to render your own content, or change the default content and title that it gives you.

import { AuthPage } from "@refinedev/antd";

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

FAQ

How can I remove the default title and logo ?

You can use the renderContent property to remove the default title and logo.

import { AuthPage } from "@refinedev/antd";

const MyLoginPage = () => {
return (
<AuthPage
type="login"
renderContent={(
content: React.ReactNode,
title: React.ReactNode, // not return
) => {
return content;
}}
/>
);
};

Or you can give false to the title property to remove the default title.

import { AuthPage } from "@refinedev/antd";

const MyLoginPage = () => {
return (
<AuthPage
type="login"
title={false}
/>
);
};

API Reference

Properties

Interface

interface OAuthProvider {
name: string;
icon?: React.ReactNode;
label?: string;
}