Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Add auth hooks #3368

Merged
merged 18 commits into from
Jul 1, 2019
Merged

[RFR] Add auth hooks #3368

merged 18 commits into from
Jul 1, 2019

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Jun 26, 2019

  • [BC Break] Store authProvider in modern React context instead of legacy context
  • Add useAuth() hook (replacement for <Authenticated>)
  • Add usePermissions() hook (replacement for <WithPermissions>)
  • use usePermissions instead of WithPermissions in <Resource> (we need an intermediate component because hooks can't execute inside a render function)
  • Use the new hooks in examples
  • Update documentation
  • Update upgrade guide
import { useAuth } from 'react-admin';

const CustomRoutes = [
    <Route path="/foo" render={() => {
        useAuth();
        return <Foo />;
    }} />,
    <Route path="/bar" render={() => {
        const { authenticated } = useAuth(
            { myContext: 'foobar' }, 
            { logoutOnFailure: false }
        );
        return authenticated ? <Bar /> : <BarNotAuthenticated />;
    }} />,
];
const App = () => (
    <Admin customRoutes={customRoutes}>
        ...
    </Admin>
);
import { usePermissions } from 'react-admin';

const PostDetail = props => {
    const { loaded, permissions } = usePermissions();
    if (loaded && permissions == 'editor') {
        return <PostEdit {...props} />
    } else {
        return <PostShow {...props} />
    }
};

@fzaninotto fzaninotto changed the title [WIP] Add auth hooks [RFR] Add auth hooks Jun 28, 2019
@fzaninotto
Copy link
Member Author

Switching to RFR

@fzaninotto fzaninotto added this to the 3.0.0 milestone Jun 28, 2019
docs/Authorization.md Outdated Show resolved Hide resolved
Co-Authored-By: Gildas Garcia <[email protected]>
@djhi djhi merged commit a6ce952 into next Jul 1, 2019
@djhi
Copy link
Collaborator

djhi commented Jul 1, 2019

🔥

@djhi djhi deleted the auth-hooks branch July 1, 2019 07:44
@fzaninotto fzaninotto mentioned this pull request Jul 1, 2019
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants