<AuthPage>
component from refine for Chakra 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.
You can swizzle this component to customize it with the refine CLI
Usage <AuthPage>
component can be used like this:
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine routerProvider = { { ... routerProvider , routes : [ { path : "/register" , element : < AuthPage type = " register " /> , } , { path : "/forgot-password" , element : < AuthPage type = " forgotPassword " /> , } , ] , } } authProvider = { authProvider } LoginPage = { AuthPage } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
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.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine routerProvider = { routerProvider } authProvider = { authProvider } LoginPage = { AuthPage } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
After form submission, the login
method of the authProvider
will be called with the form values.
import { AuthProvider } from "@pankod/refine-core" ; const authProvider : AuthProvider = { login : async ( { email , password , remember , providerName } ) => { return Promise . resolve ( ) ; return Promise . reject ( ) ; } , } ;
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"
:
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { { ... routerProvider , routes : [ { path : "/register" , element : < AuthPage type = " register " /> , } , ] , } } LoginPage = { AuthPage } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
After form submission, the register
method of the authProvider
will be called with the form values.
import { AuthProvider } from "@pankod/refine-core" ; const authProvider : AuthProvider = { register : async ( { email , password , providerName } ) => { return Promise . resolve ( ) ; return Promise . reject ( ) ; } , } ;
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
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { { ... routerProvider , routes : [ { path : "/forgot-password" , element : < AuthPage type = " forgotPassword " /> , } , ] , } } LoginPage = { AuthPage } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
After form submission, the forgotPassword
method of the authProvider
will be called with the form values.
import { AuthProvider } from "@pankod/refine-core" ; const authProvider : AuthProvider = { forgotPassword : async ( { email } ) => { return Promise . resolve ( ) ; return Promise . reject ( ) ; } , } ;
UpdatePassword The updatePassword
type is the page used to update the password of the user.
localhost:3000/update-password
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { { ... routerProvider , routes : [ { path : "/update-password" , element : < AuthPage type = " updatePassword " /> , } , ] , } } LoginPage = { AuthPage } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
After form submission, the updatePassword
method of the authProvider
will be called with the form values.
import { AuthProvider } from "@pankod/refine-core" ; const authProvider : AuthProvider = { updatePassword : async ( { password , confirmPassword } ) => { return Promise . resolve ( ) ; return Promise . reject ( ) ; } , } ;
Props providers
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.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useRouterContext , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { routerProvider } LoginPage = { ( ) => ( < AuthPage providers = { [ { name : "google" , icon : GoogleIcon , label : "Sign in with Google" , } , { name : "github" , icon : GithubIcon , label : "Sign in with GitHub" , } , ] } /> ) } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
rememberMe
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.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout , Form , FormControlLabel , Checkbox , } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { useFormContext } from "@pankod/refine-react-hook-form" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const RememberMe = ( ) => { const { register } = useFormContext ( ) ; return < Checkbox { ... register ( "rememberMe" ) } > Remember Me </ Checkbox > ; } ; const App = ( ) => { return ( < Refine routerProvider = { routerProvider } authProvider = { authProvider } LoginPage = { ( ) => < AuthPage rememberMe = { < RememberMe /> } /> } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
loginLink
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. Default value is "/login"
.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useRouterContext } from "@pankod/refine-core" ; import { AuthPage , Layout , Box } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const Auth = ( props ) => { const { Link } = useRouterContext ( ) ; return ( < AuthPage { ... props } loginLink = { < Box mb = " 3 " bg = " gray.200 " > < Link to = " /login " > Login </ Link > </ Box > } /> ) ; } ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { { ... routerProvider , routes : [ { path : "/register" , element : < Auth type = " register " /> , } , ] , } } LoginPage = { Auth } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
registerLink
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. Default value is "/register"
.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useRouterContext } from "@pankod/refine-core" ; import { AuthPage , Layout , Box } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const Auth = ( props ) => { const { Link } = useRouterContext ( ) ; return ( < AuthPage { ... props } registerLink = { < Box mb = " 3 " bg = " gray.200 " > < Link to = " /register " > Register </ Link > </ Box > } /> ) ; } ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { { ... routerProvider , routes : [ { path : "/register" , element : < Auth type = " register " /> } ] , } } LoginPage = { Auth } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
forgotPasswordLink
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. Default value is "/forgot-password"
.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useRouterContext } from "@pankod/refine-core" ; import { AuthPage , Layout , Box } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const Auth = ( props ) => { const { Link } = useRouterContext ( ) ; return ( < AuthPage { ... props } forgotPasswordLink = { < Box mb = " 3 " bg = " gray.200 " > < Link to = " /register " > Forgot Password </ Link > </ Box > } /> ) ; } ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { { ... routerProvider , routes : [ { path : "/forgot-password" , element : < Auth type = " forgotPassword " /> , } , ] , } } LoginPage = { Auth } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
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
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine authProvider = { authProvider } routerProvider = { routerProvider } LoginPage = { ( ) => ( < AuthPage wrapperProps = { { bg : "tomato" , } } /> ) } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
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
.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine routerProvider = { routerProvider } authProvider = { authProvider } LoginPage = { ( ) => ( < AuthPage contentProps = { { bg : "tomato" , } } /> ) } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } /> ) ; } ;
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.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useNavigation } from "@pankod/refine-core" ; import { AuthPage , Layout } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine routerProvider = { routerProvider } authProvider = { authProvider } LoginPage = { ( ) => ( < AuthPage formProps = { { defaultValues : { email : "test@mail.com" , } , onSubmit : ( e : any ) => { e . preventDefault ( ) ; console . log ( "e" , e . target . email . value ) ; const email = e . target . email . value ; const password = e . target . password . value ; alert ( JSON . stringify ( { email , password , } ) , ) ; } , } } / > ) } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } / > ) ; } ;
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.
Live previews only work with the latest documentation.
Show Code Hide Code import { Refine , useRouterContext } from "@pankod/refine-core" ; import { AuthPage , Layout , Box , Heading } from "@pankod/refine-chakra-ui" ; import routerProvider from "@pankod/refine-react-router-v6" ; import { authProvider } from "./authProvider" ; import { DashboardPage } from "./pages/dashboard" ; const App = ( ) => { return ( < Refine routerProvider = { routerProvider } authProvider = { authProvider } LoginPage = { ( ) => ( < AuthPage contentProps = { { style : { width : "400px" , } , } } renderContent = { ( content : React . ReactNode ) => { return ( < Box bg = " white " borderRadius = " md " px = " 5 " display = " flex " flexDirection = " column " justifyContent = " center " alignItems = " center " > < Heading color = " white " > Extra Header </ Heading > { content } < Heading color = " white " > Extra Footer </ Heading > </ Box > ) ; } } /> ) } DashboardPage = { DashboardPage } Layout = { Layout } resources = { [ { name : "posts" } ] } / > ) ; } ;
API Reference Properties Property Description Type type Render <AuthPage>
forms by type
property. login
| register
| forgotPassword
| updatePassword
providers Render auth logins if type
is "login"
. IProvider[]
registerLink A custom node that will be rendered as a register link to the <AuthPage>
. React.ReactNode
loginLink A custom node that will be rendered as a link to the <AuthPage>
. React.ReactNode
forgotPasswordLink A custom node that will be rendered as a forgot password link to the <AuthPage>
. React.ReactNode
wrapperProps Wrapper element props. BoxProps
contentProps Content wrapper element props. BoxProps
formProps Props for the form component. [FormPropsType
] renderContent Gives you default content you can use it to add some extra elements to the content. function(content: React.ReactNode) => React.ReactNode
Interface interface OAuthProvider { name : string ; icon ? : React . ReactNode ; label ? : string ; }
import { UseFormProps } from "@pankod/refine-react-hook-form" ; interface FormPropsType extends UseFormProps { onSubmit ? : ( values : any ) => void ; }