首页 > 解决方案 > How to implement forgot password page on react-admin

问题描述

I have a dashboard implemented on react-admin. The authentication process was done following this tutorial.

Now I need to implement a forgot password screen, but the problem is that this screen needs to be accessible without being logged in...

I thought of 2 possible ways to implement this:

  1. Ideally I would like to configure react-admin to allow unauthenticated access to a particular route. Not sure on how to do this, or if it is possible... I found this Github issue mentioning this as an enhancement, but it does not explain how to get around the issue.
  2. Implement this screen separately in react and handle routing to this page separately. Not sure on how to do this on the framework either...

Can someone explain how to implement either option on the framework?

Thanks in advance,

标签: reactjsreact-admin

解决方案


Based on a comment on the Github issue, I ended up implementing a workaround based on the simple example.

The main thing I did was to add a few custom routes with the noLayout option. These custom routes do not seem to go through authentication for some reason I could not find in the documentation.

So, I redefined my App.js file:

const App = () => (
  <Admin
        loginPage={Login}
        authProvider={authProvider}
        dataProvider={dataProvider}
        i18nProvider={i18nProvider}
        title="Example Admin"
        locale="en"
        customReducers={{ tree }}
        customRoutes={[
            <Route exact path="/forgotPassword" component={ForgotPassword} noLayout/>,
            <Route exact path="/resetPassword" component={ResetPassword} noLayout/>,
        ]}
    >
        {permissions => [
            <Resource name="users" {...users} />,
        ]}
  </Admin>
);

Anyways, this is the solution I came up with, not sure if it is the right one. Please let me know if you find something better.


推荐阅读