OIDC React comes with hooks! Hooks are a great way, much better then using our Consumer.
useAuth returns the same as our authContext. Let's look at an example of use.
import { useAuth } from 'oidc-react';
export default () => {
const auth = useAuth();
return <p>Hello {auth.profile.name}!</p>;
};
The example above uses id_token
object (profile
) and displays the name of
the user.
It should be as easy as that!