Skip to content

Commit

Permalink
Merge pull request #2622 from marmelab/disable-login
Browse files Browse the repository at this point in the history
[RFR] Allow to disable the login route and component
  • Loading branch information
fzaninotto committed Dec 5, 2018
2 parents 3614216 + 31bd099 commit 7b628dd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
38 changes: 21 additions & 17 deletions docs/Admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@ export default App;

Here are all the props accepted by the component:

* [`dataProvider`](#dataprovider)
* [`title`](#title)
* [`dashboard`](#dashboard)
* [`catchAll`](#catchall)
* [`menu`](#menu) (deprecated)
* [`theme`](#theme)
* [`appLayout`](#applayout)
* [`customReducers`](#customreducers)
* [`customSagas`](#customsagas)
* [`customRoutes`](#customroutes)
* [`authProvider`](#authprovider)
* [`loginPage`](#loginpage)
* [`logoutButton`](#logoutbutton)
* [`locale`](#internationalization)
* [`messages`](#internationalization)
* [`initialState`](#initialstate)
* [`history`](#history)
- [The `<Admin>` Component](#the-admin-component)
- [`dataProvider`](#dataprovider)
- [`title`](#title)
- [`dashboard`](#dashboard)
- [`catchAll`](#catchall)
- [`menu`](#menu)
- [`theme`](#theme)
- [`appLayout`](#applayout)
- [`customReducers`](#customreducers)
- [`customSagas`](#customsagas)
- [`customRoutes`](#customroutes)
- [`authProvider`](#authprovider)
- [`loginPage`](#loginpage)
- [`logoutButton`](#logoutbutton)
- [`initialState`](#initialstate)
- [`history`](#history)
- [Internationalization](#internationalization)
- [Declaring resources at runtime](#declaring-resources-at-runtime)
- [Using react-admin without `<Admin>` and `<Resource>`](#using-react-admin-without-admin-and-resource)

## `dataProvider`

Expand Down Expand Up @@ -471,6 +473,8 @@ const App = () => (
);
```

You can also disable it completely along with the `/login` route by passing `false` to this prop.

See The [Authentication documentation](./Authentication.md#customizing-the-login-and-logout-components) for more details.

## `logoutButton`
Expand Down
32 changes: 20 additions & 12 deletions packages/ra-core/src/CoreAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface Props {
initialState: object;
loading: ComponentType;
locale: string;
loginPage: ComponentType;
loginPage: ComponentType | boolean;
logoutButton: ComponentType;
menu: ComponentType;
theme: object;
Expand Down Expand Up @@ -85,21 +85,29 @@ React-admin requires a valid dataProvider function to work.`);

const logout = authProvider ? createElement(logoutButton) : null;

if (loginPage === true && process.env.NODE_ENV !== 'production') {
console.warn(
'You passed true to the loginPage prop. You must either pass false to disable it or a component class to customize it'
);
}

return (
<TranslationProvider>
<ConnectedRouter history={this.history}>
<Switch>
<Route
exact
path="/login"
render={props =>
createElement(loginPage, {
...props,
title,
theme,
})
}
/>
{loginPage !== false ? (
<Route
exact
path="/login"
render={props =>
createElement(loginPage as ComponentType, {
...props,
title,
theme,
})
}
/>
) : null}
<Route
path="/"
render={props => (
Expand Down

0 comments on commit 7b628dd

Please sign in to comment.