sensitive-blue
sensitive-blue4y ago

Extending AuthPage

Anyone have any suggestions on how to extend the AuthPage's RegisterPage to include additional input fields?
14 Replies
sunny-green
sunny-green4y ago
I guess you have to create your own authpage with registration and login page.
sunny-green
sunny-green4y ago
| refine
component from refine is a authentication page that can be used to login, register, forgot password and update password.
sunny-green
sunny-green4y ago
export const AuthPage: React.FC<AuthProps> = (props) => {
const { type } = props;
const renderView = () => {
switch (type) {
case "register":
return <RegisterPage {...props} />;
case "forgotPassword":
return <ForgotPasswordPage {...props} />;
case "updatePassword":
return <UpdatePasswordPage {...props} />;
default:
return <LoginPage {...props} />;
}
};

return <>{renderView()}</>;
};
export const AuthPage: React.FC<AuthProps> = (props) => {
const { type } = props;
const renderView = () => {
switch (type) {
case "register":
return <RegisterPage {...props} />;
case "forgotPassword":
return <ForgotPasswordPage {...props} />;
case "updatePassword":
return <UpdatePasswordPage {...props} />;
default:
return <LoginPage {...props} />;
}
};

return <>{renderView()}</>;
};
This is refines core AuthPage. You can create your own same as above and update only the RegisterPage as you desire. And use it in the Refine component LoginPage as
const App = () => {
return (
<Refine
authProvider={authProvider}
LoginPage={AuthPage} # <<<======== Your custom AuthPage goes here
resources={[{ name: "posts" }]}
/>
);
};
const App = () => {
return (
<Refine
authProvider={authProvider}
LoginPage={AuthPage} # <<<======== Your custom AuthPage goes here
resources={[{ name: "posts" }]}
/>
);
};
sensitive-blue
sensitive-blueOP4y ago
Womp womp Ya I tried to copy the core auth page but there were some errors (maybe some typing error)
Omer
Omer4y ago
Could you share error details?
sensitive-blue
sensitive-blueOP4y ago
No description
Omer
Omer4y ago
GitHub
refine/index.tsx at next · refinedev/refine
Build your React-based CRUD applications, without constraints. - refine/index.tsx at next · refinedev/refine
sensitive-blue
sensitive-blueOP4y ago
same as the register component:
import { useForm } from "@pankod/refine-react-hook-form";
import { useForm } from "@pankod/refine-react-hook-form";
Omer
Omer4y ago
Hmm. Could you share StackBlitz env?
sensitive-blue
sensitive-blueOP4y ago
Omer
Omer4y ago
Thanks ⚡️ We will look at it tomorrow
passive-yellow
passive-yellow4y ago
Hey @geekdev, useFormProps is compatible with useForm from the @pankod/refine-core package so you have to pass the useFormProps to refineCoreProps for @pankod/refine-react-hook-form package like below:
const {
register,
handleSubmit,
formState: { errors },
} = useForm<BaseRecord, HttpError, RegisterFormTypes>({
refineCoreProps: {
...useFormProps,
}
});
const {
register,
handleSubmit,
formState: { errors },
} = useForm<BaseRecord, HttpError, RegisterFormTypes>({
refineCoreProps: {
...useFormProps,
}
});
sensitive-blue
sensitive-blueOP4y ago
Ahh thanks! I see what I did wrong now. I imported from the wrong package. I should done like https://github.com/refinedev/refine/blob/ef3122b79d008d7fe4b85d6a1e5a1441e3cdeb75/packages/mui/src/components/pages/auth/index.tsx#L4:
import { UseFormProps } from "@pankod/refine-react-hook-form";
import { UseFormProps } from "@pankod/refine-react-hook-form";
thanks for catching that!
passive-yellow
passive-yellow4y ago
Nice to hear that! But you are right there is a little conflict. We’ll disscuss the case with team tomorrow. 🙏🏼

Did you find this page helpful?